# Final Project Format
# The final report should be presented in more formal format. Consider your audience to be non data analysts. Fellow data analysts (i.e. students) will be able to access your R Markdown file for details on the analysis. Submit a Zip file with your R Markdown file, the HTML output, and any supplementary files (e.g. data, figures, etc.). You must address the five following sections:
#
# Introduction: What is your research question? Why do you care? Why should others care?
#
# Data: Write about the data from your proposal in text form. Address the following points:
#
# Data collection: Describe how the data were collected.
# Cases: What are the cases? (Remember: case = units of observation or units of experiment)
# Variables: What are the two variables you will be studying? State the type of each variable.
# Type of study: What is the type of study, observational or an experiment? Explain how you've arrived at your conclusion using information on the sampling and/or experimental design.
# Scope of inference - generalizability: Identify the population of interest, and whether the findings from this analysis can be generalized to that population, or, if not, a subsection of that population. Explain why or why not. Also discuss any potential sources of bias that might prevent generalizability.
# Scope of inference - causality: Can these data be used to establish causal links between the variables of interest? Explain why or why not.
# Exploratory data analysis: Perform relevant descriptive statistics, including summary statistics and visualization of the data. Also address what the exploratory data analysis suggests about your research question.
#
# Inference: If your data fails some conditions and you can't use a theoretical method, then you should use simulation. If you can use both methods, then you should use both methods. It is your responsibility to figure out the appropriate methodology.
#
# Check conditions
# Theoretical inference (if possible) - hypothesis test and confidence interval
# Simulation based inference - hypothesis test and confidence interval
# Brief description of methodology that reflects your conceptual understanding
# Conclusion: Write a brief summary of your findings without repeating your statements from earlier. Also include a discussion of what you have learned about your research question and the data you collected. You may also want to include ideas for possible future research.
#
This is Sales data of from last 2 year, grouped by location and and quarter info.
What is your research question? Why do you care? Why should others care?
Approach :
Data : (Write about the data from your proposal in text form. Address the following points:) Data collection: (Describe how the data were collected.) This data is sample of sales by promotion for last two year. Data was shared by Marketting team to evaluate the sales performance.
Note : For Confidencilaty names and numbers have been changed in the data.
Cases : What are the cases? (Remember: case = units of observation or units of experiment) In This sample we have 1000 rows. Each row identify the Order from the given customer.
Variables : What are the two variables you will be studying? State the type of each variable.
Order Quantity is Response variable here . It’s Quantitative variable. Quarter Qt, is Independent varible , it’s qualitative variable as we can’t add them. Other qualitative variables: Brands,Promotions, Zipcode etc.
Type of study : What is the type of study, observational or an experiment? Explain how you’ve arrived at your conclusion using information on the sampling and/or experimental design.
We do studies to gather information and draw conclusions. The type of conclusion we draw depends on the study method used: In an observational study, we measure or survey members of a sample without trying to affect them. In a controlled experiment, we assign people or things to groups and apply some treatment to one of the groups, while the other group does not receive the treatment.
This is an observational study.
Scope of inference - generalizability: Identify the population of interest, and whether the findings from this analysis can be generalized to that population, or, if not, a subsection of that population. Explain why or why not. Also discuss any potential sources of bias that might prevent generalizability.
Since data set is too big and would take too much computing power and machine time. To save time I’ll be working on sample data of much smaller size. on computing I am keeping my sample size to 200 * 8 (each quarter from 2 year). These findings may be generlaized for the same customer and identify the posibility of sales .
Scope of inference - causality: Can these data be used to establish causal links between the variables of interest? Explain why or why not. Since its a observational study we can’t make Casue and Effect inference from here, but it being an observational study it will have some info about customers spending pttern over the years and Quarter.
#---------------------------------------------------------------------
# Create Sample A of 1000 customer
#---------------------------------------------------------------------
custA <- mkt_cust_qt[sample(nrow(mkt_cust_qt),1000),]
custAG <- gather(custA, key = "Qt",value = "order_unit",-KUNNR_NEW)
custAG$KUNNR_NEW <- as.character(custAG$KUNNR_NEW)
custAG$Qt = as.factor(custAG$Qt)
custAG$order_unit[which(is.na(custAG$order_unit))] <- 0
custAG$seq <- 0
custAG$seq[which(custAG$Qt=="Q1_17")] = 1
custAG$seq[which(custAG$Qt=="Q2_17")] = 2
custAG$seq[which(custAG$Qt=="Q3_17")] = 3
custAG$seq[which(custAG$Qt=="Q4_17")] = 4
custAG$seq[which(custAG$Qt=="Q1_18")] = 5
custAG$seq[which(custAG$Qt=="Q2_18")] = 6
custAG$seq[which(custAG$Qt=="Q3_18")] = 7
custAG$seq[which(custAG$Qt=="Q4_18")] = 8
custAG <- custAG[order(custAG$seq),]
#---------------------------------------------------------------------
# Create Sample A of 1000 customer
#---------------------------------------------------------------------
# Wide Data set
head(custA)
# Long Data set
head(custAG)
Perform relevant descriptive statistics, including summary statistics and visualization of the data. Also address what the exploratory data analysis suggests about your research question.
# Data
str(head(mkt_Data[,-c(1,2,3,4,5,6,7,8,7)]))
## Classes 'tbl_df', 'tbl' and 'data.frame': 6 obs. of 15 variables:
## $ Brand : chr "RJ" "RB" "RX" "RX" ...
## $ Order Number : num 2.02e+09 2.02e+09 2.02e+09 2.02e+09 1.50e+08 ...
## $ Order Date : POSIXct, format: "2018-05-10" "2017-03-10" ...
## $ Order Quantity : num 1 13 51 6 54 2
## $ Promotion Order Doll: num 31.9 1120.2 3555.3 398.3 3813.8 ...
## $ Promotion : num 70 59 57 70 114782 ...
## $ External Description: chr "Other" "UP3" "NASC150" "Other" ...
## $ Ship Sets : chr "S" "S" "S" "S" ...
## $ From Date : POSIXct, format: "2018-05-01" "2017-01-03" ...
## $ To Date : POSIXct, format: "2018-05-31" "2017-03-31" ...
## $ city : chr "OKLAHOMA CITY" "SOUTHLAKE" "LOS ANGELES" "SPRINGFIELD" ...
## $ state : chr "OK" "TX" "CA" "OH" ...
## $ zip : chr "73170" "76092" "90066-4923" "45503" ...
## $ Qt : chr "Q2_18" "Q1_17" "Q2_17" "Q4_17" ...
## $ KUNNR_NEW : chr "1256111" "1258760" "1251146" "1262300" ...
summary((mkt_Data[,-c(1,2,3,4,5,6,7,8,7)]))
## Brand Order Number Order Date
## Length:5000 Min. :1.481e+08 Min. :2017-01-03 00:00:00
## Class :character 1st Qu.:2.016e+09 1st Qu.:2017-06-29 00:00:00
## Mode :character Median :2.018e+09 Median :2018-01-17 00:00:00
## Mean :1.578e+09 Mean :2017-12-31 19:47:42
## 3rd Qu.:2.020e+09 3rd Qu.:2018-06-22 00:00:00
## Max. :2.402e+09 Max. :2018-12-29 00:00:00
## Order Quantity Promotion Order Doll Promotion
## Min. : 1.00 Min. : 0.0 Min. : 14
## 1st Qu.: 5.00 1st Qu.: 343.9 1st Qu.: 68
## Median : 10.00 Median : 737.1 Median : 106
## Mean : 14.68 Mean : 1102.9 Mean : 27220
## 3rd Qu.: 18.00 3rd Qu.: 1367.1 3rd Qu.: 241
## Max. :690.00 Max. :41197.7 Max. :114916
## External Description Ship Sets From Date
## Length:5000 Length:5000 Min. :2017-01-03 00:00:00
## Class :character Class :character 1st Qu.:2017-06-01 00:00:00
## Mode :character Mode :character Median :2018-01-01 00:00:00
## Mean :2017-12-01 03:56:44
## 3rd Qu.:2018-06-01 00:00:00
## Max. :2018-10-01 00:00:00
## To Date city state
## Min. :2017-03-31 00:00:00 Length:5000 Length:5000
## 1st Qu.:2017-07-05 00:00:00 Class :character Class :character
## Median :2018-01-31 00:00:00 Mode :character Mode :character
## Mean :2018-01-30 05:17:05
## 3rd Qu.:2018-07-30 00:00:00
## Max. :2018-12-31 00:00:00
## zip Qt KUNNR_NEW
## Length:5000 Length:5000 Length:5000
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
head(mkt_Data[,-c(1,2,3,4,5,6,7,8,7)])
describe.by(custA)
## Warning: describe.by is deprecated. Please use the describeBy function
## Warning in describeBy(x = x, group = group, mat = mat, type = type, ...):
## no grouping variable requested
ggplot(custAG,mapping = aes(x=KUNNR_NEW ,y= order_unit, color=Qt)) + geom_point()
ggplot(custAG[which(custAG$order_unit<= 100),],mapping = aes(y=KUNNR_NEW ,x= order_unit, color=Qt)) + geom_point() + facet_wrap(~Qt,ncol = 2) + ggtitle("Ordered Unit < 150 by Customer ") + ylab("Customer")
ggplot(custAG[which(custAG$order_unit> 100),],mapping = aes(y=KUNNR_NEW ,x= order_unit, color=Qt)) + geom_point() + facet_wrap(~Qt,ncol = 2) + ggtitle("Ordered Unit >150 by Customer ") + ylab("Customer")
# Graph by Plotly
plot_ly(data=custAG,y=custAG$order_unit ,x= custAG$KUNNR_NEW,color=custAG$Qt, type= "scatter") %>% layout( title = "scatter plot: Customer Order Qty by Quarter")
## No scatter mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode
# plot_ly(data=custAG,y=custAG$order_unit ,x= custAG$KUNNR_NEW, z = custAG$Qt ,color=custAG$Qt, type= "scatter3d" )
custAG %>%
group_by(Qt) %>% summarise(order_unit = sum(order_unit)) %>%
ggplot(mapping = aes(x= Qt,y=order_unit,fill = Qt)) + geom_col() + geom_label(aes(label=order_unit))+
theme_light() + ggtitle("Order Quantity Over Each Quarter") +ylab("Ordered Unit") + xlab("Quarter")
# Line plot with multiple groups
custAG[order(custAG$seq),] %>%
ggplot( aes(x= seq, y=order_unit, group= KUNNR_NEW,color=Qt) )+
geom_line()+
geom_point() + ggtitle("Customer Order Qty Movement over Quarter")
If your data fails some conditions and you can’t use a theoretical method, then you should use simulation. If you can use both methods, then you should use both methods. It is your responsibility to figure out the appropriate methodology.
We will examine sample of data after tidying of the data in the below formt :
| Customer | Q1 | Q2 |
|---|---|---|
| 1 | 21 | 12 |
| 2 | 21 | 12 |
| 3 | 21 | 12 |
| 4 | 21 | 12 |
| . | . | . |
| . | . | . |
| n | n | n |
Note : # Check conditions # Theoretical inference (if possible) - hypothesis test and confidence interval # Simulation based inference - hypothesis test and confidence interval # Brief description of methodology that reflects your conceptual understanding
Oneway ANOVA Test & Results There are several ways to do so but let’s start with the simplest from the base R first ‘aov’. While it’s possible to wrap the command in a summary or print statement I saved the results out to an R object in this case ‘AOV_RESULT’.
The dependent variable goes to the left of the tilde and our independent or predictor variable to the right. aov is not limited to Oneway ANOVA so adding additional factors is possible. Steps:
1. Set the Hypothesis
2. Run the AOV test 3. Peforming eta squared test 3. Interpred the result and Check condition 4. Check with Paired t test. ##### Prepare H0 = Quarter doesn’t matter in predicting Order Quantity -all Quarters are the same H1 = At least one of the Quarter populations is different than the others. Our null is basically
If Pvalue is less than that of Alpha .05 we will rejct the null Hypothesis.
Rewording: H0: There is no difference between qunatity of Q1_17,Q2_17 and so on and so forth. pq1 = pq2 = pq3 …
HA: There is a difference between qunatity of Q1_17,Q2_17 and so on and so forth.
# # custAG[order(custAG$seq),] %>%spread(key = Qt,value = order_unit, fill=0)
# custAG[order(custAG$seq),] %>%spread(key = Qt,value = order_unit, fill=0)
# Creating QUarter data over each column
# Q1 Q2 Q3 ...
# 1 2 3 ...
# 1 2 3 ...
# 1 2 3 ...
#Conbined Data
Dt_ANOVA <- custAG[,c(3,2)]
Dt_ANOVA2017 <- Dt_ANOVA[which(Dt_ANOVA$Qt %in% c("Q1_17", "Q2_17", "Q3_17" ,"Q4_17")),]
boxplot(Dt_ANOVA2017$order_unit~Dt_ANOVA2017$Qt,
main="Boxplot comparing Qty of Quarter",
col= rainbow(4),
horizontal = TRUE)
library(Hmisc)
## Warning: package 'Hmisc' was built under R version 3.5.3
## Loading required package: lattice
## Loading required package: survival
## Loading required package: Formula
## Warning: package 'Formula' was built under R version 3.5.2
##
## Attaching package: 'Hmisc'
## The following object is masked from 'package:plotly':
##
## subplot
## The following object is masked from 'package:psych':
##
## describe
## The following objects are masked from 'package:dplyr':
##
## src, summarize
## The following objects are masked from 'package:base':
##
## format.pval, units
ggplot(Dt_ANOVA2017, aes(reorder(Qt,order_unit),order_unit,fill=Qt))+
# ggplot(tyre, aes(Brands,Mileage,fill=Brands))+ # if you want to leave them alphabetic
geom_jitter(colour = "dark gray",width=.1) +
stat_boxplot(geom ='errorbar',width = 0.4) +
geom_boxplot()+
labs(title="Boxplot, dotplot and SEM plot of mileage for four Quarters of Sales",
x = "Quarter (sorted)",
y = "Sales",
subtitle ="Gray dots=sample data points, Black dot=outlier, Blue dot=mean, Red=99% confidence interval",
caption = "No Major obvious difference in mean is noted") +
guides(fill=FALSE) +
stat_summary(fun.data = "mean_cl_normal", colour = "red", size = 1.5, fun.args = list(conf.int=.99)) +
stat_summary(geom="point", fun.y=mean, color="blue") +
theme_bw()
All_Qt_row <- custA[,-c(1)]
head(All_Qt_row)
summary(All_Qt_row)
## Q1_17 Q1_18 Q2_17 Q2_18
## Min. : 1.000 Min. : 1.000 Min. : 1.00 Min. : 1.000
## 1st Qu.: 1.000 1st Qu.: 1.000 1st Qu.: 1.00 1st Qu.: 1.000
## Median : 1.000 Median : 1.000 Median : 1.00 Median : 1.000
## Mean : 3.438 Mean : 3.399 Mean : 3.66 Mean : 3.143
## 3rd Qu.: 1.000 3rd Qu.: 1.000 3rd Qu.: 1.00 3rd Qu.: 1.000
## Max. :156.000 Max. :100.000 Max. :690.00 Max. :157.000
## Q3_17 Q3_18 Q4_17 Q4_18
## Min. : 1.000 Min. : 1.000 Min. : 1.000 Min. : 1.00
## 1st Qu.: 1.000 1st Qu.: 1.000 1st Qu.: 1.000 1st Qu.: 1.00
## Median : 1.000 Median : 1.000 Median : 1.000 Median : 1.00
## Mean : 3.388 Mean : 2.911 Mean : 2.841 Mean : 2.87
## 3rd Qu.: 1.000 3rd Qu.: 1.000 3rd Qu.: 1.000 3rd Qu.: 1.00
## Max. :202.000 Max. :60.000 Max. :113.000 Max. :129.00
# Creating stacked quarter data.
# Q1
# Q2
# Q3
All_Qt_stack <- custAG[,c(3,2)]
head(All_Qt_stack,n=10)
print(t(describe.by(All_Qt_stack)))
## Warning: describe.by is deprecated. Please use the describeBy function
## Warning in describeBy(x = x, group = group, mat = mat, type = type, ...):
## no grouping variable requested
## order_unit Qt*
## vars 1.0000000 2.00000000
## n 8000.0000000 8000.00000000
## mean 3.2062500 4.50000000
## sd 11.0693734 2.29143107
## median 1.0000000 4.50000000
## trimmed 1.2306250 4.50000000
## mad 0.0000000 2.96520000
## min 1.0000000 1.00000000
## max 690.0000000 8.00000000
## range 689.0000000 7.00000000
## skew 33.1106825 0.00000000
## kurtosis 1884.7791671 -1.23853569
## se 0.1237594 0.02561898
head(All_Qt_stack)
AOV_RESULT <- aov(order_unit~Qt,All_Qt_stack) # Qt is predictor
class(AOV_RESULT)
## [1] "aov" "lm"
# The names command will give you some sense of all the information contained in the list object.
names(AOV_RESULT)
## [1] "coefficients" "residuals" "effects" "rank"
## [5] "fitted.values" "assign" "qr" "df.residual"
## [9] "contrasts" "xlevels" "call" "terms"
## [13] "model"
# The summary command gives us the key ANOVA data we need and produces a classic ANOVA table
summary(AOV_RESULT)
## Df Sum Sq Mean Sq F value Pr(>F)
## Qt 7 667 95.35 0.778 0.606
## Residuals 7992 979458 122.55
# One-way ANOVA showed a no significant effect of Quarter on Order Quantity gain (F(7, 7992) = 1.504 , , p a .001).
print( AOV_RESULT )
## Call:
## aov(formula = order_unit ~ Qt, data = All_Qt_stack)
##
## Terms:
## Qt Residuals
## Sum of Squares 667.4 979458.3
## Deg. of Freedom 7 7992
##
## Residual standard error: 11.07045
## Estimated effects may be unbalanced
F-test is always one sided
And that we only reject the null hypothesis for very large F-values
That means we’re only interested in the upper tail of the F-distribution
pf( 1.504, 7, 7992,lower.tail=FALSE)
## [1] 0.1607537
# R doesn't use the names "between-group"
# and "within-group". Instead, it tries to assign more meaningful names: in our case # "between groups" variance corresponds to the effect that the "Qt" has on the outcome variable; "within groups" variance is corresponds to the "leftover" variability, so it calls that the residuals
# There's a few different ways you could measure the effect size in an ANOVA, but the most commonly
# used measures are ??2 (eta squared) and partial ??2. For a one way analysis of variance they're identical
# to each other, so for the moment I'll just explain ??2. The definition of ??2 is actually really simple
SSb <- 3473
SSt <- (3473+2636684) # total sums of squares
# eta squared
# The interpretation of ??2 (eta squared) is equally straightforward: it refers to the proportion of the variability in the
# outcome variable (Order_Quantity) that can be explained in terms of the predictor (Quarter).
# A value of ??2 ((eta squared) = 0
# means that there is no relationship at all between the two,
# whereas a value of ??2 (eta squared) = 1 means that the relationship is perfect.
# eta_Sqrd <- sqrt(SSb / SSt)
eta_Sqrd <- sqrt(SSb / SSt) # eta-squared value
eta_Sqrd
## [1] 0.03626916
###
Here we can conclude that there is no strong relation between the order Qty over Quarter.
We have assumed 3 things; independence, homogeneity of variance (homoscedasticity) and normality for considering ANOVA result for our probelm. Lets see if our result meets these conditions.
Independence : Eacu customer is indendent and buying pattern is too.
our errors or residuals are normally distributed : Our Residual is Right Skewed as its just the promotion sales data.
The final is homogeneity of variance also known as (homoscedasticity). : Due to some big outlier the sample is not showing the plot , but we can asumet this based on small sample size .
# Plot each one by one
par(mfrow=c(2,2))
plot(AOV_RESULT)
#PLotting Residual only
hist(AOV_RESULT$residuals)
# homoscedasticity
plot(AOV_RESULT$residuals)
print(t(psych::describe(AOV_RESULT$residuals) ))# skew kurtosis are very high , which shows that data is not fully normalised , given the sample size we will
## X1
## vars 1.000000e+00
## n 8.000000e+03
## mean 1.649811e-15
## sd 1.106560e+01
## median -2.143000e+00
## trimmed -1.918803e+00
## mad 4.047498e-01
## min -2.660000e+00
## max 6.863400e+02
## range 6.890000e+02
## skew 3.307924e+01
## kurtosis 1.882381e+03
## se 1.237172e-01
#using sample of size 500 to see data.
par(mfrow=c(2,2))
for (i in 1:10)
{
AOV_RESULT_Sam <- aov(order_unit~Qt,(Dt_ANOVA[sample(nrow(Dt_ANOVA),500),]))
plot(AOV_RESULT_Sam$residuals)
}
It’s tempting to conclude that Q1 is better than the other Quarters. Afetr running multiple T test , it was clear that the pvalue 0.0178 < 0.05 , so we can reject null hypothesis. Suport atlernate hypothesis that there is evidence of a difference in sleas of Quarter 1 and Quarter 2.
Please Note : I have done pairewise t test using function but not sure how to iterpret the result . Including it for future study.
# How we can say which quarter is more or less in terms of data
library(gplots)
## Warning: package 'gplots' was built under R version 3.5.3
##
## Attaching package: 'gplots'
## The following object is masked from 'package:stats':
##
## lowess
plotmeans( formula = order_unit~Qt, # plot Order Qty by Quarter
data = All_Qt_stack, # the data frame
xlab = "Quarter", # x-axis label
ylab = "Order Qty", # y-axis label
n.label = FALSE # don't display sample size
)
plotmeans( formula = order_unit~seq, # plot Order Qty by Quarter
data = custAG[,c(3,4,2)], # the data frame
xlab = "Quarter", # x-axis label
ylab = "Order Qty", # y-axis label
n.label = FALSE # don't display sample size,
)
# it's tempting to conclude that Q1 is better than the other Quarters excpet Q2 and better than Anxifree,
# but there's no real difference between each quarter. However, if we want to get a clearer
# answer about this, it might help to run some tests.
#Running "pairwise" t-tests
# set p.adjust.method = "none" since we're not doing any adjustments.
pairwise.t.test(x = Dt_ANOVA$order_unit,
g = Dt_ANOVA$Qt,
p.adjust.method = "none")
##
## Pairwise comparisons using t tests with pooled SD
##
## data: Dt_ANOVA$order_unit and Dt_ANOVA$Qt
##
## Q1_17 Q1_18 Q2_17 Q2_18 Q3_17 Q3_18 Q4_17
## Q1_18 0.937 - - - - - -
## Q2_17 0.654 0.598 - - - - -
## Q2_18 0.551 0.605 0.296 - - - -
## Q3_17 0.920 0.982 0.583 0.621 - - -
## Q3_18 0.287 0.324 0.130 0.639 0.335 - -
## Q4_17 0.228 0.260 0.098 0.542 0.269 0.888 -
## Q4_18 0.251 0.285 0.111 0.581 0.295 0.934 0.953
##
## P value adjustment method: none
library(DATA606)
## Loading required package: shiny
## Warning: package 'shiny' was built under R version 3.5.3
##
## Attaching package: 'shiny'
## The following objects are masked from 'package:DT':
##
## dataTableOutput, renderDataTable
## Loading required package: openintro
## Warning: package 'openintro' was built under R version 3.5.2
## Please visit openintro.org for free statistics materials
##
## Attaching package: 'openintro'
## The following object is masked from 'package:survival':
##
## transplant
## The following object is masked from 'package:lattice':
##
## lsegments
## The following object is masked from 'package:ggplot2':
##
## diamonds
## The following objects are masked from 'package:datasets':
##
## cars, trees
## Loading required package: OIdata
## Warning: package 'OIdata' was built under R version 3.5.3
## Loading required package: RCurl
## Warning: package 'RCurl' was built under R version 3.5.2
## Loading required package: bitops
##
## Attaching package: 'RCurl'
## The following object is masked from 'package:tidyr':
##
## complete
## Loading required package: maps
## Warning: package 'maps' was built under R version 3.5.2
##
## Attaching package: 'maps'
## The following object is masked from 'package:purrr':
##
## map
## Loading required package: markdown
##
## Welcome to CUNY DATA606 Statistics and Probability for Data Analytics
## This package is designed to support this course. The text book used
## is OpenIntro Statistics, 3rd Edition. You can read this by typing
## vignette('os3') or visit www.OpenIntro.org.
##
## The getLabs() function will return a list of the labs available.
##
## The demo(package='DATA606') will list the demos that are available.
##
## Attaching package: 'DATA606'
## The following object is masked from 'package:utils':
##
## demo
Dt_ANOVA2017_q12 <- Dt_ANOVA2017[which(Dt_ANOVA2017$Qt %in% c("Q1_17","Q2_17")),]
Dt_ANOVA2017_q12$Qt <- factor(Dt_ANOVA2017_q12$Qt)
inference(y = as.numeric(Dt_ANOVA2017_q12$order_unit),
x = Dt_ANOVA2017_q12$Qt, est = "mean", type = "ht", null = 0,
alternative = "greater", method = "theoretical")
## Warning: package 'BHH2' was built under R version 3.5.3
## Response variable: numerical, Explanatory variable: categorical
## Difference between two means
## Summary statistics:
## n_Q1_17 = 1000, mean_Q1_17 = 3.438, sd_Q1_17 = 9.678
## n_Q2_17 = 1000, mean_Q2_17 = 3.66, sd_Q2_17 = 22.7591
## Observed difference between means (Q1_17-Q2_17) = -0.222
##
## H0: mu_Q1_17 - mu_Q2_17 = 0
## HA: mu_Q1_17 - mu_Q2_17 > 0
## Standard error = 0.782
## Test statistic: Z = -0.284
## p-value = 0.6117
Dt_ANOVA2017_q23 <- Dt_ANOVA2017[which(Dt_ANOVA2017$Qt %in% c("Q2_17","Q3_17")),]
Dt_ANOVA2017_q23$Qt <- factor(Dt_ANOVA2017_q23$Qt)
inference(y = as.numeric(Dt_ANOVA2017_q23$order_unit),
x = Dt_ANOVA2017_q23$Qt, est = "mean", type = "ht", null = 0,
alternative = "greater", method = "theoretical")
## Response variable: numerical, Explanatory variable: categorical
## Difference between two means
## Summary statistics:
## n_Q2_17 = 1000, mean_Q2_17 = 3.66, sd_Q2_17 = 22.7591
## n_Q3_17 = 1000, mean_Q3_17 = 3.388, sd_Q3_17 = 10.4132
## Observed difference between means (Q2_17-Q3_17) = 0.272
##
## H0: mu_Q2_17 - mu_Q3_17 = 0
## HA: mu_Q2_17 - mu_Q3_17 > 0
## Standard error = 0.791
## Test statistic: Z = 0.344
## p-value = 0.3655
Dt_ANOVA2017_q34 <- Dt_ANOVA2017[which(Dt_ANOVA2017$Qt %in% c("Q3_17","Q4_17")),]
Dt_ANOVA2017_q34$Qt <- factor(Dt_ANOVA2017_q34$Qt)
inference(y = as.numeric(Dt_ANOVA2017_q34$order_unit),
x = Dt_ANOVA2017_q34$Qt, est = "mean", type = "ht", null = 0,
alternative = "greater", method = "theoretical")
## Response variable: numerical, Explanatory variable: categorical
## Difference between two means
## Summary statistics:
## n_Q3_17 = 1000, mean_Q3_17 = 3.388, sd_Q3_17 = 10.4132
## n_Q4_17 = 1000, mean_Q4_17 = 2.841, sd_Q4_17 = 6.561
## Observed difference between means (Q3_17-Q4_17) = 0.547
##
## H0: mu_Q3_17 - mu_Q4_17 = 0
## HA: mu_Q3_17 - mu_Q4_17 > 0
## Standard error = 0.389
## Test statistic: Z = 1.405
## p-value = 0.0799
# (t.test( formula = Dt_ANOVA2017_q12$order_unit ~ Dt_ANOVA2017_q12$Qt,
# data = Dt_ANOVA2017,
# subset = Qt %in% c("Q1_17","Q2_17"),
# var.equal = TRUE
# ))
# Suppose that my post hoc analysis consists of m separate tests, and I want to ensure
# that the total probability of making any Type I errors at all is at most ??.9 If so, then the Bonferroni
# correction just says "multiply all your raw p-values by m". If we let p denote the original p-value, and
# let p1
# j be the corrected value, then the Bonferroni correction tells that:
# p1 " m ^ p
# And therefore, if you're using the Bonferroni correction, you would reject the null hypothesis if p1 a ??.
# The logic behind this correction is very straightforward. We're doing m different tests; so if we arrange
# it so that each test has a Type I error rate of at most ??{m, then the total Type I error rate across these
# tests cannot be larger than ??.
# here we have 8 Quaters data so comb(8,2) = 28 , with this method all the results were multiplied by 28
pairwise.t.test(x = Dt_ANOVA$order_unit,
g = Dt_ANOVA$Qt,
p.adjust.method = "bonferroni")
##
## Pairwise comparisons using t tests with pooled SD
##
## data: Dt_ANOVA$order_unit and Dt_ANOVA$Qt
##
## Q1_17 Q1_18 Q2_17 Q2_18 Q3_17 Q3_18 Q4_17
## Q1_18 1 - - - - - -
## Q2_17 1 1 - - - - -
## Q2_18 1 1 1 - - - -
## Q3_17 1 1 1 1 - - -
## Q3_18 1 1 1 1 1 - -
## Q4_17 1 1 1 1 1 1 -
## Q4_18 1 1 1 1 1 1 1
##
## P value adjustment method: bonferroni
Test method. Use the chi-square goodness of fit test to determine whether observed sample frequencies differ significantly from expected frequencies specified in the null hypothesis.
This approach consists of four steps: (1) state the hypotheses :
The hypotheses for the Chi-squared test are as follows.
H0: There is no association between qunatity of Q1_17,Q2_17 and so on and so forth. pq1 = pq2 = pq3 …
HA: There is an association between qunatity of Q1_17,Q2_17 and so on and so forth.
Assumptions* The chi-squared test, when used with the standard approximation that a chi-squared distribution is applicable, has the following assumptions:
Simple random sample The sample data is a random sampling from a fixed distribution or population where every collection of members of the population of the given sample size has an equal probability of selection. Variants of the test have been developed for complex samples, such as where the data is weighted. Other forms can be used such as purposive sampling.
n= 50 and 500, selcted randomly from sample . satisfying Simple Random sample
Sample size (whole table) A sample with a sufficiently large size is assumed. If a chi squared test is conducted on a sample with a smaller size, then the chi squared test will yield an inaccurate inference. The researcher, by using chi squared test on small samples, might end up committing a Type II error.
sample size is big enough and with multiple itration I have tried to get possible result.
Expected cell count Adequate expected cell counts. Some require 5 or more, and others require 10 or more. A common rule is 5 or more in all cells of a 2-by-2 table, and 5 or more in 80% of cells in larger tables, but no cells with zero expected count. When this assumption is not met, Yates’s correction is applied.
Cell count is more that 2 X 2 matrix dat value.
Independence The observations are always assumed to be independent of each other. This means chi-squared cannot be used to test correlated data.
- Each sample is choosen randonmly from the Population. We can say that they are meeting the condition on Indepenence
- Then sample of 50 and 500 was created to run the chi-test.
We will create Sample of 1000 datapoints where records are spread in column for each quarter. we would be doing regular chi square test and then we would switch to Multiple simulation
Significance level. significance levels 0.05, or 0.10; but any value between 0 and 1 can be used.
custA$KUNNR_NEW <- as.character(custA$KUNNR_NEW )
summary(custA)
## KUNNR_NEW Q1_17 Q1_18 Q2_17
## Length:1000 Min. : 1.000 Min. : 1.000 Min. : 1.00
## Class :character 1st Qu.: 1.000 1st Qu.: 1.000 1st Qu.: 1.00
## Mode :character Median : 1.000 Median : 1.000 Median : 1.00
## Mean : 3.438 Mean : 3.399 Mean : 3.66
## 3rd Qu.: 1.000 3rd Qu.: 1.000 3rd Qu.: 1.00
## Max. :156.000 Max. :100.000 Max. :690.00
## Q2_18 Q3_17 Q3_18 Q4_17
## Min. : 1.000 Min. : 1.000 Min. : 1.000 Min. : 1.000
## 1st Qu.: 1.000 1st Qu.: 1.000 1st Qu.: 1.000 1st Qu.: 1.000
## Median : 1.000 Median : 1.000 Median : 1.000 Median : 1.000
## Mean : 3.143 Mean : 3.388 Mean : 2.911 Mean : 2.841
## 3rd Qu.: 1.000 3rd Qu.: 1.000 3rd Qu.: 1.000 3rd Qu.: 1.000
## Max. :157.000 Max. :202.000 Max. :60.000 Max. :113.000
## Q4_18
## Min. : 1.00
## 1st Qu.: 1.00
## Median : 1.00
## Mean : 2.87
## 3rd Qu.: 1.00
## Max. :129.00
head(custA)
# List test condtion for CHi-Square
# 1. Are the value independent for each Quarter :
# 2.
# Ho : Customer are not baised on speding over Quarter . pq1 = pq2 = pq3 ...
# Ha : Customer are spending less or more compared to last quarter.
# 1. convert the data as a table with only Quater data .
dt <- as.table(as.matrix(custA[,]))
# Test 1
chi_custA <- custA[1:50,c(2,4,6,8,3,5,7,9)] %>%
chisq.test(test_custA)
## Warning in chisq.test(., test_custA): Chi-squared approximation may be
## incorrect
chi_custA
##
## Pearson's Chi-squared test
##
## data: .
## X-squared = 2895, df = 343, p-value < 2.2e-16
head(chi_custA$observed)
## Q1_17 Q2_17 Q3_17 Q4_17 Q1_18 Q2_18 Q3_18 Q4_18
## [1,] 1 1 1 1 1 6 1 1
## [2,] 1 1 1 1 1 1 1 9
## [3,] 1 1 1 1 1 1 24 1
## [4,] 1 8 56 1 20 1 1 11
## [5,] 1 1 1 1 2 1 1 1
## [6,] 1 1 1 1 1 9 1 1
head(chi_custA$expected)
## Q1_17 Q2_17 Q3_17 Q4_17 Q1_18 Q2_18 Q3_18
## [1,] 1.1253092 1.018137 1.993405 1.489695 1.843364 1.971970 2.229184
## [2,] 1.3849959 1.253092 2.453421 1.833471 2.268755 2.427040 2.743611
## [3,] 2.6834295 2.427865 4.753504 3.552350 4.395713 4.702391 5.315746
## [4,] 8.5696620 7.753504 15.180544 11.344600 14.037923 15.017312 16.976092
## [5,] 0.7790602 0.704864 1.380049 1.031327 1.276175 1.365210 1.543281
## [6,] 1.3849959 1.253092 2.453421 1.833471 2.268755 2.427040 2.743611
## Q4_18
## [1,] 1.328937
## [2,] 1.635614
## [3,] 3.169002
## [4,] 10.120363
## [5,] 0.920033
## [6,] 1.635614
plot(chi_custA$residuals)
chi_custA <- custA[1:50,c(2,4,6,8,3)] %>%
chisq.test()
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
chi_custA
##
## Pearson's Chi-squared test
##
## data: .
## X-squared = 1030.9, df = 196, p-value < 2.2e-16
head(chi_custA$observed)
## Q1_17 Q2_17 Q3_17 Q4_17 Q1_18
## [1,] 1 1 1 1 1
## [2,] 1 1 1 1 1
## [3,] 1 1 1 1 1
## [4,] 1 8 56 1 20
## [5,] 1 1 1 1 2
## [6,] 1 1 1 1 1
head(chi_custA$expected)
## Q1_17 Q2_17 Q3_17 Q4_17 Q1_18
## [1,] 0.7532281 0.6814921 1.334290 0.9971306 1.233859
## [2,] 0.7532281 0.6814921 1.334290 0.9971306 1.233859
## [3,] 0.7532281 0.6814921 1.334290 0.9971306 1.233859
## [4,] 12.9555237 11.7216643 22.949785 17.1506456 21.222382
## [5,] 0.9038737 0.8177905 1.601148 1.1965567 1.480631
## [6,] 0.7532281 0.6814921 1.334290 0.9971306 1.233859
plot(chi_custA$residuals)
(gather((as.data.frame(chi_custA$residuals)),"Qt","Val")) %>% ggplot(mapping = aes(x=Qt,y= Val))+
geom_col()
# Test 2
chi_custA <- custA[sample(1:nrow(custA),500),c(2,4,6,8,3,5,7,9)] %>%
chisq.test(simulate.p.value = TRUE)
chi_custA
##
## Pearson's Chi-squared test with simulated p-value (based on 2000
## replicates)
##
## data: .
## X-squared = 38481, df = NA, p-value = 0.0004998
head(chi_custA$observed)
## Q1_17 Q2_17 Q3_17 Q4_17 Q1_18 Q2_18 Q3_18 Q4_18
## [1,] 1 1 5 1 1 1 1 1
## [2,] 40 1 1 1 1 1 1 1
## [3,] 1 1 1 1 1 13 1 1
## [4,] 1 1 1 1 1 6 1 1
## [5,] 1 17 1 1 1 1 1 1
## [6,] 1 18 1 14 1 1 1 1
head(chi_custA$expected)
## Q1_17 Q2_17 Q3_17 Q4_17 Q1_18 Q2_18 Q3_18
## [1,] 1.633503 1.963906 1.584452 1.332716 1.478019 1.417862 1.396576
## [2,] 6.397887 7.691964 6.205769 5.219806 5.788909 5.553293 5.469921
## [3,] 2.722505 3.273176 2.640753 2.221194 2.463366 2.363104 2.327626
## [4,] 1.769628 2.127564 1.716489 1.443776 1.601188 1.536017 1.512957
## [5,] 3.267006 3.927811 3.168903 2.665433 2.956039 2.835724 2.793151
## [6,] 5.172760 6.219034 5.017430 4.220268 4.680395 4.489897 4.422490
## Q4_18
## [1,] 1.192966
## [2,] 4.672451
## [3,] 1.988277
## [4,] 1.292380
## [5,] 2.385932
## [6,] 3.777726
round(chi_custA$residuals, 3)
## Q1_17 Q2_17 Q3_17 Q4_17 Q1_18 Q2_18 Q3_18 Q4_18
## [1,] -0.496 -0.688 2.713 -0.288 -0.393 -0.351 -0.336 -0.177
## [2,] 13.285 -2.413 -2.090 -1.847 -1.990 -1.932 -1.911 -1.699
## [3,] -1.044 -1.256 -1.010 -0.819 -0.932 6.919 -0.870 -0.701
## [4,] -0.579 -0.773 -0.547 -0.369 -0.475 3.602 -0.417 -0.257
## [5,] -1.254 6.596 -1.218 -1.020 -1.138 -1.090 -1.073 -0.897
## [6,] -1.835 4.724 -1.794 4.761 -1.701 -1.647 -1.627 -1.429
## [7,] 4.623 -1.000 -0.765 -0.583 -0.691 -0.648 -0.632 -0.468
## [8,] -0.085 -0.270 -0.055 0.118 0.015 0.056 0.071 0.230
## [9,] 6.141 -2.843 -1.076 -2.219 -2.376 -0.450 -0.788 4.035
## [10,] -1.440 -1.674 -1.403 10.145 -1.319 -1.269 -1.251 -1.069
## [11,] -0.085 -0.270 -0.055 0.118 0.015 0.056 0.071 0.230
## [12,] -0.406 1.639 -0.375 -0.201 -0.305 -0.263 -0.248 -0.089
## [13,] -0.729 -0.929 -0.697 -0.516 4.526 -0.580 -0.564 -0.402
## [14,] -0.085 -0.270 -0.055 0.118 0.015 0.056 0.071 0.230
## [15,] -1.396 -1.626 -1.358 -1.154 9.144 -1.226 -1.209 -1.028
## [16,] -1.396 -1.626 -1.358 -1.154 9.144 -1.226 -1.209 -1.028
## [17,] -1.608 -1.851 -1.569 -1.355 -1.482 10.912 -1.412 -1.223
## [18,] 1.380 -1.256 -1.010 4.548 -0.932 -0.887 -0.870 -0.701
## [19,] -1.254 -1.477 -1.218 -1.020 -1.138 -1.090 8.501 -0.897
## [20,] -1.567 -1.808 -1.529 -1.317 -1.442 -1.391 10.736 -1.186
## [21,] -2.179 -3.667 20.036 -2.922 -3.109 -3.033 -3.005 -2.730
## [22,] 14.064 -2.543 -2.210 -1.960 -2.107 -2.047 -2.026 -1.808
## [23,] -1.567 -1.808 9.839 -1.317 -1.442 -1.391 -1.373 -1.186
## [24,] -0.986 5.042 -0.953 -0.764 -0.876 -0.831 -0.815 -0.647
## [25,] -0.926 -1.134 5.594 -0.707 -0.817 -0.773 -0.756 -0.590
## [26,] -1.044 -1.256 -1.010 -0.819 6.713 -0.887 -0.870 -0.701
## [27,] -0.496 -0.688 2.713 -0.288 -0.393 -0.351 -0.336 -0.177
## [28,] -1.973 -2.240 -1.930 -1.697 -1.835 13.484 -1.759 -1.554
## [29,] 9.086 -1.720 -1.446 -1.237 -1.361 -1.311 -1.293 -1.109
## [30,] -0.496 -0.688 -0.464 -0.288 2.897 -0.351 -0.336 -0.177
## [31,] -0.579 -0.773 3.269 -0.369 -0.475 -0.432 -0.417 -0.257
## [32,] -0.986 -1.196 -0.953 -0.764 -0.876 -0.831 6.583 -0.647
## [33,] -0.203 -0.390 -0.173 0.000 -0.103 -0.061 -0.046 1.168
## [34,] -1.440 -1.674 8.999 -1.196 -1.319 -1.269 -1.251 -1.069
## [35,] -0.203 -0.390 -0.173 1.001 -0.103 -0.061 -0.046 0.111
## [36,] -1.608 -1.851 -1.569 11.376 -1.482 -1.430 -1.412 -1.223
## [37,] -0.085 -0.270 -0.055 0.118 0.015 0.056 0.071 0.230
## [38,] -0.203 -0.390 -0.173 0.000 -0.103 -0.061 -0.046 1.168
## [39,] 5.560 -1.578 -1.313 -1.111 1.563 -1.182 -1.165 -0.986
## [40,] -1.725 3.456 -1.685 -1.464 -1.595 5.343 -1.523 -1.329
## [41,] -1.799 -2.054 -1.758 -1.534 11.918 -1.613 -1.593 -1.396
## [42,] -0.798 -1.000 -0.765 5.419 -0.691 -0.648 -0.632 -0.468
## [43,] -0.496 -0.688 -0.464 -0.288 -0.393 -0.351 3.049 -0.177
## [44,] -0.864 -1.068 -0.831 -0.646 -0.756 -0.712 5.703 -0.531
## [45,] -1.254 -1.477 -1.218 -1.020 -1.138 -1.090 -1.073 9.461
## [46,] -0.203 -0.390 -0.173 0.000 -0.103 -0.061 0.931 0.111
## [47,] -0.085 -0.270 -0.055 0.118 0.015 0.056 0.071 0.230
## [48,] -3.151 -3.508 -3.094 -2.787 11.695 4.903 -0.982 -2.601
## [49,] -2.103 -2.379 -2.059 7.473 -1.960 5.390 -1.882 -1.671
## [50,] -0.085 -0.270 -0.055 0.118 0.015 0.056 0.071 0.230
## [51,] -1.044 -1.256 6.375 -0.819 -0.932 -0.887 -0.870 -0.701
## [52,] -0.729 -0.929 -0.697 -0.516 -0.624 -0.580 4.734 -0.402
## [53,] 1.408 4.404 -1.266 -1.066 -1.185 -1.137 -1.119 -0.942
## [54,] -0.579 -0.773 -0.547 -0.369 -0.475 -0.432 3.648 -0.257
## [55,] -2.342 -2.636 7.816 -2.041 5.176 -2.130 -2.108 -1.885
## [56,] -0.579 -0.773 -0.547 -0.369 -0.475 -0.432 3.648 -0.257
## [57,] -0.729 -0.929 4.277 -0.516 -0.624 -0.580 -0.564 -0.402
## [58,] -1.526 -1.764 -1.488 -1.277 7.442 1.304 -1.333 -1.148
## [59,] 4.170 -0.929 -0.697 -0.516 -0.624 -0.580 -0.564 -0.402
## [60,] 9.891 -1.851 -1.569 -1.355 -1.482 -1.430 -1.412 -1.223
## [61,] -0.864 -1.068 -0.831 -0.646 5.464 -0.712 -0.696 -0.531
## [62,] -1.204 -1.425 7.439 -0.973 -1.089 -1.042 -1.025 -0.851
## [63,] -0.496 -0.688 -0.464 -0.288 -0.393 3.008 -0.336 -0.177
## [64,] 8.515 -1.626 -1.358 -1.154 -1.275 -1.226 -1.209 -1.028
## [65,] -0.656 3.111 -0.624 -0.445 -0.552 -0.509 -0.493 -0.332
## [66,] -0.310 1.066 -0.279 -0.105 -0.209 -0.167 -0.152 0.006
## [67,] -1.044 -1.256 -1.010 -0.819 -0.932 -0.887 -0.870 7.809
## [68,] -1.799 -2.054 -1.758 -1.534 -1.666 -1.613 -1.593 13.724
## [69,] -1.762 -2.015 -1.722 -1.499 -1.631 -1.578 -1.558 13.438
## [70,] -0.203 -0.390 -0.173 0.000 -0.103 0.908 -0.046 0.111
## [71,] -3.298 -3.667 -3.239 -2.922 -3.109 -3.033 -3.005 25.403
## [72,] -0.579 -0.773 2.506 -0.369 -0.475 -0.432 0.396 -0.257
## [73,] -0.656 -0.853 -0.624 -0.445 -0.552 -0.509 4.207 -0.332
## [74,] -1.254 -1.477 -1.218 -1.020 8.168 -1.090 -1.073 -0.897
## [75,] 5.853 -1.196 -0.953 -0.764 -0.876 -0.831 -0.815 -0.647
## [76,] 15.858 -2.843 -2.486 -2.219 -2.376 -2.312 -2.289 -2.056
## [77,] -0.729 -0.929 -0.697 4.908 -0.624 -0.580 -0.564 -0.402
## [78,] -0.729 3.539 -0.697 -0.516 -0.624 -0.580 -0.564 -0.402
## [79,] -0.310 -0.498 -0.279 -0.105 -0.209 -0.167 1.702 0.006
## [80,] -0.864 -1.068 -0.831 -0.646 -0.756 -0.712 -0.696 6.392
## [81,] 0.700 -0.390 -0.173 0.000 -0.103 -0.061 -0.046 0.111
## [82,] -0.864 -1.068 -0.831 -0.646 -0.756 -0.712 5.703 -0.531
## [83,] 6.229 -1.256 -1.010 -0.819 -0.932 -0.887 -0.870 -0.701
## [84,] -0.986 -1.196 -0.953 6.808 -0.876 -0.831 -0.815 -0.647
## [85,] -0.496 -0.688 2.713 -0.288 -0.393 -0.351 -0.336 -0.177
## [86,] 2.327 -1.808 2.920 -1.317 -1.442 -1.391 -1.373 2.232
## [87,] 3.317 -1.425 2.848 -0.973 -1.089 -1.042 -1.025 -0.851
## [88,] -1.044 -1.256 6.375 -0.819 -0.932 -0.887 -0.870 -0.701
## [89,] -0.496 -0.688 2.713 -0.288 -0.393 -0.351 -0.336 -0.177
## [90,] 9.891 -1.851 -1.569 -1.355 -1.482 -1.430 -1.412 -1.223
## [91,] -0.085 -0.270 -0.055 0.118 0.015 0.056 0.071 0.230
## [92,] -0.656 -0.853 -0.624 4.367 -0.552 -0.509 -0.493 -0.332
## [93,] -0.864 -1.068 -0.831 -0.646 5.464 -0.712 -0.696 -0.531
## [94,] -0.496 -0.688 -0.464 -0.288 -0.393 3.008 -0.336 -0.177
## [95,] -0.864 -1.068 -0.831 -0.646 5.464 -0.712 -0.696 -0.531
## [96,] -2.134 -2.413 -2.090 -1.847 -1.990 -1.932 -1.911 16.343
## [97,] -1.099 5.698 -1.065 -0.872 -0.986 -0.940 -0.924 -0.753
## [98,] 6.590 -1.314 -1.065 -0.872 -0.986 -0.940 -0.924 -0.753
## [99,] 4.410 -2.204 0.682 -1.665 0.868 -1.747 1.020 -1.524
## [100,] -2.195 11.646 -2.150 -1.904 -2.050 -1.991 -1.969 -1.301
## [101,] -0.310 -0.498 -0.279 1.793 -0.209 -0.167 -0.152 0.006
## [102,] -1.044 -1.256 -1.010 -0.819 6.713 -0.887 -0.870 -0.701
## [103,] -2.134 -2.413 -2.090 -1.847 -1.990 -1.932 -1.911 16.343
## [104,] -1.204 -1.425 -1.169 8.413 -1.089 -1.042 -1.025 -0.851
## [105,] -1.350 -1.578 -1.313 -1.111 8.828 -1.182 -1.165 -0.986
## [106,] -3.019 16.409 -2.965 -2.666 -2.842 -2.447 -2.745 -2.485
## [107,] -0.926 -1.134 -0.893 -0.707 5.899 -0.773 -0.756 -0.590
## [108,] 0.287 1.453 -0.464 -0.288 -0.393 -0.351 -0.336 -0.177
## [109,] -0.986 -1.196 -0.953 -0.764 -0.876 6.511 -0.815 -0.647
## [110,] 2.045 -0.596 -0.375 -0.201 -0.305 -0.263 -0.248 -0.089
## [111,] -0.496 -0.688 -0.464 -0.288 -0.393 3.008 -0.336 -0.177
## [112,] 3.180 -0.773 -0.547 -0.369 -0.475 -0.432 -0.417 -0.257
## [113,] -1.436 9.744 -1.829 -1.601 -1.735 -1.681 -1.661 -1.461
## [114,] -1.762 -2.015 -1.722 -1.499 -1.631 -1.578 12.121 -1.363
## [115,] -0.310 -0.498 -0.279 1.793 -0.209 -0.167 -0.152 0.006
## [116,] -1.687 -1.935 -1.647 -1.429 -1.558 5.978 -1.487 4.689
## [117,] -1.153 -1.370 -1.118 -0.923 7.466 -0.992 -0.975 -0.803
## [118,] -0.579 -0.773 -0.547 -0.369 -0.475 -0.432 3.648 -0.257
## [119,] -1.044 -1.256 -1.010 -0.819 -0.932 -0.887 -0.870 7.809
## [120,] -0.496 2.166 -0.464 -0.288 -0.393 -0.351 -0.336 -0.177
## [121,] -0.986 5.042 -0.953 -0.764 -0.876 -0.831 -0.815 -0.647
## [122,] -0.085 -0.270 -0.055 0.118 0.015 0.056 0.071 0.230
## [123,] -1.153 -1.370 -1.118 -0.923 -1.039 -0.992 7.774 -0.803
## [124,] -2.835 8.405 -2.783 -2.496 -2.665 -2.596 -2.572 6.957
## [125,] 1.197 -3.366 -2.965 -2.666 -2.842 9.836 3.769 -2.485
## [126,] -0.864 -1.068 5.176 -0.646 -0.756 -0.712 -0.696 -0.531
## [127,] -0.798 -1.000 -0.765 5.419 -0.691 -0.648 -0.632 -0.468
## [128,] -1.044 -1.256 -1.010 7.232 -0.932 -0.887 -0.870 -0.701
## [129,] 0.700 -0.390 -0.173 0.000 -0.103 -0.061 -0.046 0.111
## [130,] -1.153 -1.370 7.097 -0.923 -1.039 -0.992 -0.975 -0.803
## [131,] 3.180 -0.773 -0.547 -0.369 -0.475 -0.432 -0.417 -0.257
## [132,] -0.864 -1.068 -0.831 -0.646 -0.756 -0.712 5.703 -0.531
## [133,] -0.656 -0.853 -0.624 -0.445 -0.552 -0.509 -0.493 4.754
## [134,] -1.350 -1.578 3.544 4.186 -1.231 -1.182 -1.165 -0.986
## [135,] -1.396 7.412 -1.358 -1.154 -1.275 -1.226 -1.209 -1.028
## [136,] -0.864 -1.068 -0.831 -0.646 -0.756 -0.712 -0.696 6.392
## [137,] -1.396 -1.626 -1.358 -1.154 9.144 -1.226 -1.209 -1.028
## [138,] -1.648 -1.894 6.057 1.220 -1.520 -1.468 0.592 -1.259
## [139,] -1.204 -1.425 -1.169 -0.973 -1.089 -1.042 -1.025 9.069
## [140,] -0.496 -0.688 2.713 -0.288 -0.393 -0.351 -0.336 -0.177
## [141,] -1.440 -1.674 -1.403 -1.196 -1.319 5.328 3.180 -1.069
## [142,] -0.798 -1.000 4.739 -0.583 -0.691 -0.648 -0.632 -0.468
## [143,] -1.153 -1.370 0.056 -0.923 -1.039 -0.992 6.524 -0.803
## [144,] -1.484 -1.261 -1.446 -1.237 3.401 4.632 -1.293 -1.109
## [145,] 10.645 -1.976 -1.685 -1.464 -1.595 -1.542 -1.523 -1.329
## [146,] -1.153 -1.370 -1.118 -0.923 7.466 -0.992 -0.975 -0.803
## [147,] -1.905 -2.168 -1.863 6.907 -1.769 -1.714 -1.694 5.528
## [148,] -0.085 -0.270 -0.055 0.118 0.015 0.056 0.071 0.230
## [149,] 9.891 -1.851 -1.569 -1.355 -1.482 -1.430 -1.412 -1.223
## [150,] -1.440 -1.674 -1.403 -1.196 9.451 -1.269 -1.251 -1.069
## [151,] -0.496 -0.688 -0.464 -0.288 -0.393 -0.351 -0.336 3.486
## [152,] 4.823 -0.551 -0.893 -0.707 -0.817 -0.773 -0.756 -0.590
## [153,] -2.134 -2.413 -2.090 2.530 -1.990 -1.932 10.488 -1.699
## [154,] 3.180 -0.773 -0.547 -0.369 -0.475 -0.432 -0.417 -0.257
## [155,] 6.937 -1.370 -1.118 -0.923 -1.039 -0.992 -0.975 -0.803
## [156,] -1.303 -1.528 8.090 -1.066 -1.185 -1.137 -1.119 -0.942
## [157,] -1.153 -1.370 -1.118 -0.923 -1.039 7.691 -0.975 -0.803
## [158,] -0.310 -0.498 -0.279 -0.105 -0.209 -0.167 -0.152 2.012
## [159,] -1.973 10.728 -1.930 -1.697 -1.835 -1.779 -1.759 -1.554
## [160,] -0.579 -0.773 -0.547 -0.369 -0.475 3.602 -0.417 -0.257
## [161,] -2.039 -2.311 -1.995 -1.758 -1.898 -1.842 -1.821 15.600
## [162,] -1.254 -1.477 2.714 -1.020 4.097 -1.090 -1.073 -0.897
## [163,] -1.044 -1.256 -1.010 -0.819 -0.932 -0.887 6.995 -0.701
## [164,] 1.405 -0.498 -0.279 -0.105 -0.209 -0.167 -0.152 0.006
## [165,] 0.700 -0.390 -0.173 0.000 -0.103 -0.061 -0.046 0.111
## [166,] -0.798 -1.000 -0.765 -0.583 5.007 -0.648 -0.632 -0.468
## [167,] -0.579 1.969 -0.547 -0.369 -0.475 -0.432 -0.417 0.622
## [168,] -0.496 2.166 -0.464 -0.288 -0.393 -0.351 -0.336 -0.177
## [169,] 6.590 -1.314 -1.065 -0.872 -0.986 -0.940 -0.924 -0.753
## [170,] -0.579 -0.773 3.269 -0.369 -0.475 -0.432 -0.417 -0.257
## [171,] -1.396 -1.626 -1.358 -1.154 9.144 -1.226 -1.209 -1.028
## [172,] -1.153 6.008 -1.118 -0.923 -1.039 -0.992 -0.975 -0.803
## [173,] -0.986 -1.196 -0.953 -0.764 -0.876 6.511 -0.815 -0.647
## [174,] -0.310 1.066 -0.279 -0.105 -0.209 -0.167 -0.152 0.006
## [175,] -0.864 -1.068 -0.831 -0.646 -0.756 -0.712 5.703 -0.531
## [176,] -1.835 -2.093 -1.794 -1.568 -1.701 -1.647 12.638 -1.429
## [177,] 1.060 -2.955 -2.588 -2.315 -2.476 -2.410 14.338 -2.149
## [178,] -0.085 -0.270 -0.055 0.118 0.015 0.056 0.071 0.230
## [179,] -1.303 -1.528 -1.266 -1.066 -1.185 8.754 -1.119 -0.942
## [180,] -0.310 -0.498 -0.279 -0.105 1.593 -0.167 -0.152 0.006
## [181,] 2.045 -0.596 -0.375 -0.201 -0.305 -0.263 -0.248 -0.089
## [182,] -0.864 -1.068 -0.831 -0.646 5.464 -0.712 -0.696 -0.531
## [183,] -1.254 -1.477 -1.218 2.042 -1.138 -1.090 5.509 -0.897
## [184,] -0.406 -0.596 -0.375 -0.201 -0.305 -0.263 2.404 -0.089
## [185,] -0.579 -0.773 -0.547 3.792 -0.475 -0.432 -0.417 -0.257
## [186,] -1.303 -1.528 -1.266 -1.066 -1.185 8.754 -1.119 -0.942
## [187,] -1.567 -1.808 -1.529 -1.317 -1.442 10.626 -1.373 -1.186
## [188,] -1.350 7.148 -1.313 -1.111 -1.231 -1.182 -1.165 -0.986
## [189,] -1.153 -1.370 -1.118 8.033 -1.039 -0.992 -0.975 -0.803
## [190,] -1.870 -2.131 -1.829 13.295 -1.735 -1.681 -1.661 -1.461
## [191,] -0.085 -0.270 -0.055 0.118 0.015 0.056 0.071 0.230
## [192,] -1.725 -1.976 -1.685 -1.464 11.409 -1.542 -1.523 -1.329
## [193,] -2.454 -2.756 -2.406 -2.144 -2.299 -2.236 17.032 -1.985
## [194,] -1.204 -1.425 -1.169 8.413 -1.089 -1.042 -1.025 -0.851
## [195,] 8.515 -1.626 -1.358 -1.154 -1.275 -1.226 -1.209 -1.028
## [196,] -2.952 -3.013 -2.898 -2.603 -2.777 20.022 -2.681 -2.426
## [197,] -0.926 -1.134 -0.893 6.366 -0.817 -0.773 -0.756 -0.590
## [198,] -1.440 -1.674 -1.403 -1.196 -1.319 9.727 -1.251 -1.069
## [199,] -2.714 4.758 8.684 -2.384 -2.548 -2.482 -2.458 -2.215
## [200,] -1.099 5.698 -1.065 -0.872 -0.986 -0.940 -0.924 -0.753
## [201,] -0.864 -1.068 -0.831 -0.646 5.464 -0.712 -0.696 -0.531
## [202,] -0.496 -0.688 -0.464 -0.288 -0.393 3.008 -0.336 -0.177
## [203,] -0.310 -0.498 -0.279 -0.105 -0.209 1.673 -0.152 0.006
## [204,] 7.273 -1.425 -1.169 -0.973 -1.089 -1.042 -1.025 -0.851
## [205,] 4.514 -4.684 -4.163 -3.778 19.341 -3.913 -3.880 -3.547
## [206,] -1.939 10.535 -1.897 -1.665 -1.802 -1.747 -1.727 -1.524
## [207,] -1.762 -2.015 -1.722 2.001 8.342 -1.578 -1.558 -1.363
## [208,] 2.634 -0.688 -0.464 -0.288 -0.393 -0.351 -0.336 -0.177
## [209,] -1.350 -1.578 -1.313 -1.111 -1.231 -1.182 -1.165 10.210
## [210,] -0.656 -0.853 3.789 -0.445 -0.552 -0.509 -0.493 -0.332
## [211,] 24.592 -4.321 -3.834 -3.473 -3.686 -3.599 -3.568 -3.257
## [212,] -0.203 0.434 -0.173 0.000 -0.103 -0.061 -0.046 0.111
## [213,] -1.099 -1.314 -1.065 -0.872 -0.986 -0.940 7.392 -0.753
## [214,] -1.303 -1.528 -1.266 -1.066 -1.185 8.754 -1.119 -0.942
## [215,] -1.396 -1.626 -1.358 -1.154 -1.275 9.411 -1.209 -1.028
## [216,] -1.396 -1.626 -1.358 -1.154 -1.275 -1.226 9.510 -1.028
## [217,] -0.986 -1.196 -0.953 -0.764 -0.876 -0.831 -0.815 7.357
## [218,] -0.579 -0.773 -0.547 -0.369 -0.475 -0.432 3.648 -0.257
## [219,] -2.859 -3.193 -2.806 7.947 -2.688 -0.251 7.288 -2.344
## [220,] -0.656 -0.853 -0.624 4.367 -0.552 -0.509 -0.493 -0.332
## [221,] -0.203 -0.390 -0.173 0.000 0.847 -0.061 -0.046 0.111
## [222,] -0.085 -0.270 -0.055 0.118 0.015 0.056 0.071 0.230
## [223,] -2.638 -2.955 -2.588 0.663 3.532 9.136 -2.387 -2.149
## [224,] -0.986 -1.196 -0.953 -0.764 -0.876 -0.831 6.583 -0.647
## [225,] -0.579 -0.773 -0.547 -0.369 -0.475 -0.432 -0.417 4.141
## [226,] -1.608 -1.851 -1.569 -1.355 -1.482 10.912 -1.412 -1.223
## [227,] -2.481 13.627 -2.433 -2.169 -2.325 -2.262 -2.239 -2.009
## [228,] -0.986 -1.196 -0.953 -0.764 -0.876 -0.831 6.583 -0.647
## [229,] -1.799 9.731 -1.758 -1.534 -1.666 -1.613 -1.593 -1.396
## [230,] -1.153 6.008 -1.118 -0.923 -1.039 -0.992 -0.975 -0.803
## [231,] -2.285 -2.574 -2.239 -1.987 -2.136 15.676 -2.054 -1.834
## [232,] -1.905 -2.168 -1.863 -1.633 9.945 -1.714 1.087 -1.493
## [233,] -1.350 -1.578 -1.313 -1.111 6.593 -1.182 1.135 -0.986
## [234,] -2.006 -2.276 -1.963 2.391 -1.867 -1.810 -1.790 10.991
## [235,] -1.044 5.376 -1.010 -0.819 -0.932 -0.887 -0.870 -0.701
## [236,] -0.148 1.046 -1.218 -1.020 -1.138 4.254 -1.073 -0.897
## [237,] 9.891 -1.851 -1.569 -1.355 -1.482 -1.430 -1.412 -1.223
## [238,] -1.350 -1.578 -1.313 -1.111 -1.231 -1.182 -1.165 10.210
## [239,] -0.864 -1.068 -0.831 -0.646 -0.756 5.639 -0.696 -0.531
## [240,] -2.738 -3.063 -2.687 6.263 -2.572 -2.505 -2.481 11.890
## [241,] -0.203 0.434 -0.173 0.000 -0.103 -0.061 -0.046 0.111
## [242,] -0.406 -0.596 -0.375 -0.201 -0.305 -0.263 2.404 -0.089
## [243,] -1.099 -1.314 -1.065 -0.872 -0.986 -0.940 7.392 -0.753
## [244,] 3.690 -0.853 -0.624 -0.445 -0.552 -0.509 -0.493 -0.332
## [245,] -1.835 9.937 -1.794 -1.568 -1.701 -1.647 -1.627 -1.429
## [246,] -0.798 -1.000 -0.765 -0.583 -0.691 5.171 -0.632 -0.468
## [247,] -0.656 -0.853 -0.624 -0.445 -0.552 -0.509 4.207 -0.332
## [248,] -0.656 -0.853 -0.624 4.367 -0.552 -0.509 -0.493 -0.332
## [249,] -0.864 -1.068 -0.831 -0.646 5.464 -0.712 -0.696 -0.531
## [250,] -0.579 -0.773 -0.547 -0.369 -0.475 -0.432 -0.417 4.141
## [251,] 5.462 -1.134 -0.893 -0.707 -0.817 -0.773 -0.756 -0.590
## [252,] -1.725 -1.976 -1.685 -1.464 -1.595 2.392 7.891 -1.329
## [253,] -0.085 -0.270 -0.055 0.118 0.015 0.056 0.071 0.230
## [254,] -0.579 -0.773 -0.547 -0.369 -0.475 -0.432 -0.417 4.141
## [255,] -0.203 -0.390 -0.173 0.000 -0.103 -0.061 0.931 0.111
## [256,] -0.729 -0.929 -0.697 -0.516 -0.624 -0.580 -0.564 5.330
## [257,] -1.799 9.731 -1.758 -1.534 -1.666 -1.613 -1.593 -1.396
## [258,] -1.204 -1.425 -1.169 -0.973 -1.089 8.057 -1.025 -0.851
## [259,] -0.729 -0.929 -0.697 -0.516 -0.624 -0.580 4.734 -0.402
## [260,] -0.729 -0.929 -0.697 -0.516 -0.624 -0.580 4.734 -0.402
## [261,] -0.798 -1.000 -0.765 -0.583 5.007 -0.648 -0.632 -0.468
## [262,] -1.099 -1.314 -1.065 4.366 -0.986 2.234 -0.924 -0.753
## [263,] -1.204 -1.425 -1.169 -0.973 -1.089 -1.042 8.143 -0.851
## [264,] -0.656 -0.853 -0.624 -0.445 4.018 -0.509 -0.493 -0.332
## [265,] -0.864 -1.068 -0.831 -0.646 -0.756 -0.712 5.703 -0.531
## [266,] -0.729 -0.929 -0.697 -0.516 -0.624 -0.580 4.734 -0.402
## [267,] -0.926 -1.134 5.594 -0.707 -0.817 -0.773 -0.756 -0.590
## [268,] 2.045 -0.596 -0.375 -0.201 -0.305 -0.263 -0.248 -0.089
## [269,] -0.926 -1.134 -0.893 -0.707 -0.817 6.084 -0.756 -0.590
## [270,] -0.798 -1.000 -0.765 -0.583 -0.691 -0.648 5.231 -0.468
## [271,] -0.864 -1.068 5.176 -0.646 -0.756 -0.712 -0.696 -0.531
## [272,] 2.634 -0.688 -0.464 -0.288 -0.393 -0.351 -0.336 -0.177
## [273,] -1.303 -1.528 -1.266 -1.066 -1.185 8.754 -1.119 -0.942
## [274,] 5.890 -2.379 -2.059 -1.818 -1.960 -1.902 -1.882 6.746
## [275,] -0.310 -0.498 1.462 -0.105 -0.209 -0.167 -0.152 0.006
## [276,] -1.396 -1.626 -1.358 -1.154 9.144 -1.226 -1.209 -1.028
## [277,] -0.579 -0.773 3.269 -0.369 -0.475 -0.432 -0.417 -0.257
## [278,] -1.484 -1.720 -1.446 -1.237 9.751 -1.311 -1.293 -1.109
## [279,] -0.579 -0.773 -0.547 -0.369 -0.475 -0.432 3.648 -0.257
## [280,] -3.794 -4.206 -3.729 27.303 -3.584 -3.500 -3.469 -3.164
## [281,] 0.700 -0.390 -0.173 0.000 -0.103 -0.061 -0.046 0.111
## [282,] -0.310 -0.498 -0.279 -0.105 -0.209 1.673 -0.152 0.006
## [283,] -0.579 -0.773 -0.547 -0.369 3.476 -0.432 -0.417 -0.257
## [284,] -1.440 -1.674 -1.403 -1.196 4.605 -1.269 3.734 -1.069
## [285,] 3.690 -0.853 -0.624 -0.445 -0.552 -0.509 -0.493 -0.332
## [286,] -0.406 -0.596 2.114 -0.201 -0.305 -0.263 -0.248 -0.089
## [287,] -1.567 -1.808 -1.529 -1.317 -1.442 10.626 -1.373 -1.186
## [288,] -0.864 -1.068 -0.831 -0.646 -0.756 -0.712 -0.696 6.392
## [289,] -0.310 -0.498 -0.279 -0.105 -0.209 -0.167 -0.152 2.012
## [290,] -0.986 5.042 -0.953 -0.764 -0.876 -0.831 -0.815 -0.647
## [291,] 7.598 -1.477 -1.218 -1.020 -1.138 -1.090 -1.073 -0.897
## [292,] -0.729 -0.929 -0.697 -0.516 -0.624 -0.580 -0.564 5.330
## [293,] -0.864 -1.068 -0.831 -0.646 -0.756 -0.712 5.703 -0.531
## [294,] -0.496 2.166 -0.464 -0.288 -0.393 -0.351 -0.336 -0.177
## [295,] -0.798 -1.000 -0.765 -0.583 -0.691 -0.648 -0.632 5.875
## [296,] -0.926 -1.134 -0.893 -0.707 -0.817 -0.773 -0.756 6.885
## [297,] -0.085 -0.270 -0.055 0.118 0.015 0.056 0.071 0.230
## [298,] -0.496 -0.688 -0.464 -0.288 -0.393 -0.351 3.049 -0.177
## [299,] 7.472 -1.626 -1.358 -1.154 -1.275 -1.226 -1.209 0.193
## [300,] -1.044 -1.256 -1.010 -0.819 -0.932 6.919 -0.870 -0.701
## [301,] -0.926 4.693 -0.893 -0.707 -0.817 -0.773 -0.756 -0.590
## [302,] -1.648 -1.894 -1.608 -1.392 10.880 -1.468 -1.449 -1.259
## [303,] -1.396 -1.626 -1.358 -1.154 -1.275 9.411 -1.209 -1.028
## [304,] -0.406 1.639 -0.375 -0.201 -0.305 -0.263 -0.248 -0.089
## [305,] 5.202 -1.528 -1.266 -1.066 -1.185 -1.137 1.812 -0.942
## [306,] -0.496 2.166 -0.464 -0.288 -0.393 -0.351 -0.336 -0.177
## [307,] -0.926 -1.134 -0.893 -0.707 -0.817 6.084 -0.756 -0.590
## [308,] -0.496 -0.688 -0.464 3.177 -0.393 -0.351 -0.336 -0.177
## [309,] -1.396 -1.626 8.704 -1.154 -1.275 -1.226 -1.209 -1.028
## [310,] 5.853 -1.196 -0.953 -0.764 -0.876 -0.831 -0.815 -0.647
## [311,] -2.255 -2.543 -2.210 -1.960 -2.107 -2.047 15.624 -1.808
## [312,] -0.579 -0.773 -0.547 -0.369 -0.475 3.602 -0.417 -0.257
## [313,] -0.406 -0.596 2.114 -0.201 -0.305 -0.263 -0.248 -0.089
## [314,] -1.099 -1.314 -1.065 -0.872 -0.986 -0.940 3.554 3.400
## [315,] -1.567 -1.808 -1.529 11.079 -1.442 -1.391 -1.373 -1.186
## [316,] -0.864 -1.068 -0.831 -0.646 -0.756 -0.712 5.703 -0.531
## [317,] 4.623 -1.000 -0.765 -0.583 -0.691 -0.648 -0.632 -0.468
## [318,] -1.799 -2.054 -1.758 -1.534 -1.666 12.257 -1.593 -1.396
## [319,] -2.039 -2.311 0.909 11.361 -1.898 -1.842 -1.821 -1.613
## [320,] -1.440 -1.674 -0.883 -1.196 -1.319 -1.269 9.274 -1.069
## [321,] -0.579 2.655 -0.547 -0.369 -0.475 -0.432 -0.417 -0.257
## [322,] -0.085 -0.270 -0.055 0.118 0.015 0.056 0.071 0.230
## [323,] -0.496 -0.688 -0.464 -0.288 2.897 -0.351 -0.336 -0.177
## [324,] -0.203 -0.390 -0.173 0.000 -0.103 0.908 -0.046 0.111
## [325,] -1.153 -1.370 -1.118 -0.923 7.466 -0.992 -0.975 -0.803
## [326,] -0.496 -0.688 -0.464 -0.288 -0.393 -0.351 3.049 -0.177
## [327,] -0.579 -0.773 -0.547 -0.369 -0.475 -0.432 -0.417 4.141
## [328,] -0.134 -2.131 -1.829 -1.601 -1.735 10.897 -1.661 -1.461
## [329,] 3.180 -0.773 -0.547 -0.369 -0.475 -0.432 -0.417 -0.257
## [330,] -0.203 -0.390 -0.173 0.000 -0.103 0.908 -0.046 0.111
## [331,] -3.812 -4.225 -3.747 -3.393 -3.601 26.369 -3.486 -3.180
## [332,] 7.913 -1.528 -1.266 -1.066 -1.185 -1.137 -1.119 -0.942
## [333,] -1.303 -1.528 -1.266 -1.066 -1.185 -1.137 8.847 -0.942
## [334,] 6.708 -1.425 -1.169 -0.973 -1.089 -1.042 -0.414 -0.851
## [335,] 7.155 -1.578 -1.313 -1.111 -1.231 -1.182 -0.015 -0.986
## [336,] -0.864 -1.068 -0.831 -0.646 -0.756 -0.712 -0.696 6.392
## [337,] -0.798 -1.000 -0.765 5.419 -0.691 -0.648 -0.632 -0.468
## [338,] -0.406 1.639 -0.375 -0.201 -0.305 -0.263 -0.248 -0.089
## [339,] -0.986 -1.196 -0.953 -0.764 -0.876 -0.831 6.583 -0.647
## [340,] 4.170 -0.929 -0.697 -0.516 -0.624 -0.580 -0.564 -0.402
## [341,] -0.864 -1.068 -0.831 5.904 -0.756 -0.712 -0.696 -0.531
## [342,] -0.579 -0.773 3.269 -0.369 -0.475 -0.432 -0.417 -0.257
## [343,] -1.204 -1.425 -1.169 -0.973 -1.089 -1.042 8.143 -0.851
## [344,] -2.371 -2.667 -2.324 -2.067 15.839 -2.157 -2.135 -1.911
## [345,] -1.350 -1.578 -1.313 -1.111 8.828 -1.182 -1.165 -0.986
## [346,] -1.350 -1.578 8.402 -1.111 -1.231 -1.182 -1.165 -0.986
## [347,] -0.864 -1.068 -0.831 -0.646 5.464 -0.712 -0.696 -0.531
## [348,] 2.045 -0.596 -0.375 -0.201 -0.305 -0.263 -0.248 -0.089
## [349,] -1.153 -1.370 -1.118 -0.923 5.036 -0.992 1.525 -0.803
## [350,] 0.309 -1.851 -1.569 9.254 -1.482 -1.430 -1.412 -1.223
## [351,] -1.939 3.200 -1.897 7.239 -1.802 -1.747 -1.727 -1.524
## [352,] -1.303 -1.034 -1.266 -1.066 3.944 2.936 -1.119 -0.942
## [353,] -0.864 4.327 -0.831 -0.646 -0.756 -0.712 -0.696 -0.531
## [354,] 4.623 -1.000 -0.765 -0.583 -0.691 -0.648 -0.632 -0.468
## [355,] -9.778 52.865 -9.627 -6.570 -9.291 -9.096 -9.025 -8.324
## [356,] -0.798 -1.000 4.739 -0.583 -0.691 -0.648 -0.632 -0.468
## [357,] -1.762 -2.015 -1.722 -1.499 -1.631 -1.578 12.121 -1.363
## [358,] -1.725 -1.976 2.502 7.665 -1.595 -1.542 -1.523 -1.329
## [359,] -1.725 -1.976 -1.685 10.709 -1.595 -1.542 -1.523 0.279
## [360,] -0.496 -0.688 -0.464 -0.288 -0.393 3.008 -0.336 -0.177
## [361,] -1.973 -2.240 -1.930 7.101 -1.835 0.915 2.312 -1.554
## [362,] 9.891 -1.851 -1.569 -1.355 -1.482 -1.430 -1.412 -1.223
## [363,] -0.085 -0.270 -0.055 0.118 0.015 0.056 0.071 0.230
## [364,] -0.579 -0.773 -0.547 3.792 -0.475 -0.432 -0.417 -0.257
## [365,] -0.310 -0.498 -0.279 -0.105 1.593 -0.167 -0.152 0.006
## [366,] -0.656 1.790 -0.624 -0.445 0.971 -0.509 -0.493 -0.332
## [367,] -0.406 -0.596 -0.375 2.514 -0.305 -0.263 -0.248 -0.089
## [368,] -1.567 -1.808 3.414 -1.317 -1.442 -1.391 -1.373 6.219
## [369,] -0.656 -0.853 -0.624 4.367 -0.552 -0.509 -0.493 -0.332
## [370,] -1.099 -1.314 -1.065 -0.872 -0.986 -0.940 -0.924 8.244
## [371,] -0.085 -0.270 -0.055 0.118 0.015 0.056 0.071 0.230
## [372,] -0.579 2.655 -0.547 -0.369 -0.475 -0.432 -0.417 -0.257
## [373,] -0.864 -1.068 5.176 -0.646 -0.756 -0.712 -0.696 -0.531
## [374,] -0.406 -0.596 -0.375 -0.201 2.273 -0.263 -0.248 -0.089
## [375,] -1.648 8.864 -1.608 -1.392 -1.520 -1.468 -1.449 -1.259
## [376,] -1.303 -1.528 -1.266 -1.066 -1.185 8.754 -1.119 -0.942
## [377,] -1.567 3.075 -1.529 -1.317 0.093 3.311 -1.373 -1.186
## [378,] -1.044 -1.256 -1.010 7.232 -0.932 -0.887 -0.870 -0.701
## [379,] -1.484 -1.720 1.620 7.121 -1.361 -1.311 -1.293 -1.109
## [380,] -0.926 -1.134 -0.893 -0.707 -0.817 -0.773 -0.756 6.885
## [381,] -1.044 -1.256 -1.010 7.232 -0.932 -0.887 -0.870 -0.701
## [382,] 1.840 -1.808 6.380 -1.317 -1.442 -1.391 -1.373 -1.186
## [383,] 6.229 -1.256 -1.010 -0.819 -0.932 -0.887 -0.870 -0.701
## [384,] -1.608 -1.851 -1.569 -1.355 -1.482 -1.430 11.025 -1.223
## [385,] -1.044 5.376 -1.010 -0.819 -0.932 -0.887 -0.870 -0.701
## [386,] -0.496 -0.688 -0.464 -0.288 2.897 -0.351 -0.336 -0.177
## [387,] -0.798 -1.000 -0.765 -0.583 5.007 -0.648 -0.632 -0.468
## [388,] -0.406 -0.596 -0.375 2.514 -0.305 -0.263 -0.248 -0.089
## [389,] -1.396 -1.626 -1.358 9.818 -1.275 -1.226 -1.209 -1.028
## [390,] -0.926 -1.134 -0.893 6.366 -0.817 -0.773 -0.756 -0.590
## [391,] -2.454 -2.756 8.073 -2.144 -2.299 -2.236 5.870 -1.985
## [392,] -0.496 -0.688 -0.464 -0.288 2.897 -0.351 -0.336 -0.177
## [393,] -1.725 -1.976 -1.685 -1.464 -1.595 -1.542 11.855 -1.329
## [394,] -1.254 6.596 -1.218 -1.020 -1.138 -1.090 -1.073 -0.897
## [395,] -0.121 -1.000 4.051 -0.583 -0.691 -0.648 -0.632 -0.468
## [396,] 7.913 -1.528 -1.266 -1.066 -1.185 -1.137 -1.119 -0.942
## [397,] -0.729 -0.929 -0.697 -0.516 4.526 -0.580 -0.564 -0.402
## [398,] -0.310 1.066 -0.279 -0.105 -0.209 -0.167 -0.152 0.006
## [399,] -2.103 -2.379 -2.059 6.588 -1.960 6.247 -1.882 -1.671
## [400,] 3.690 -0.853 -0.624 -0.445 -0.552 -0.509 -0.493 -0.332
## [401,] -0.926 -1.134 -0.893 -0.707 -0.817 -0.773 6.153 -0.590
## [402,] -0.864 -1.068 2.507 -0.646 -0.756 -0.712 2.148 -0.531
## [403,] -0.310 -0.498 -0.279 -0.105 -0.209 1.673 -0.152 0.006
## [404,] -0.656 -0.853 -0.624 -0.445 -0.552 -0.509 4.207 -0.332
## [405,] -1.648 -1.894 -1.608 11.667 -1.520 -1.468 -1.449 -1.259
## [406,] -1.350 -1.578 -1.313 -1.111 -1.231 -1.182 -1.165 10.210
## [407,] -1.044 -1.256 5.759 -0.148 -0.932 -0.887 -0.870 -0.701
## [408,] -2.134 -2.413 13.566 -1.847 -1.990 -1.932 -1.911 -1.699
## [409,] -1.835 -2.093 -1.794 -1.568 12.166 -1.647 -1.627 -1.429
## [410,] -1.939 -2.204 12.286 -1.665 -1.802 -1.747 -1.727 -1.524
## [411,] -0.085 -0.270 -0.055 0.118 0.015 0.056 0.071 0.230
## [412,] -0.986 -1.196 5.992 -0.764 -0.876 -0.831 -0.815 -0.647
## [413,] -0.085 -0.270 -0.055 0.118 0.015 0.056 0.071 0.230
## [414,] -3.359 -3.733 21.569 -2.978 -3.167 -3.090 -3.062 -2.783
## [415,] 5.853 -1.196 -0.953 -0.764 -0.876 -0.831 -0.815 -0.647
## [416,] -0.310 -0.498 -0.279 -0.105 -0.209 -0.167 1.702 0.006
## [417,] 3.772 -2.131 6.104 -1.601 -1.735 -1.681 -1.661 -1.461
## [418,] -0.798 -1.000 4.739 -0.583 -0.691 -0.648 -0.632 -0.468
## [419,] -1.350 -1.578 -1.313 9.482 -1.231 -1.182 -1.165 -0.986
## [420,] 4.170 -0.929 -0.697 -0.516 -0.624 -0.580 -0.564 -0.402
## [421,] -0.864 -1.068 -0.831 -0.646 -0.756 5.639 -0.696 -0.531
## [422,] -1.303 -1.528 -1.266 -1.066 2.234 5.263 -1.119 -0.942
## [423,] -0.203 -0.390 -0.173 0.000 -0.103 -0.061 -0.046 1.168
## [424,] -0.406 -0.596 -0.375 -0.201 -0.305 -0.263 -0.248 2.779
## [425,] -0.798 -1.000 -0.765 -0.583 -0.691 -0.648 -0.632 5.875
## [426,] -1.350 -1.578 8.402 -1.111 -1.231 -1.182 -1.165 -0.986
## [427,] -3.379 -3.755 21.700 -2.996 -3.186 -3.109 -3.081 -2.801
## [428,] 3.690 -0.853 -0.624 -0.445 -0.552 -0.509 -0.493 -0.332
## [429,] -0.864 -1.068 -0.831 -0.646 5.464 -0.712 -0.696 -0.531
## [430,] 8.329 -4.206 -3.729 -3.377 -3.584 0.484 -3.469 10.733
## [431,] -0.729 -0.929 4.277 -0.516 -0.624 -0.580 -0.564 -0.402
## [432,] -1.099 -1.314 -1.065 6.330 -0.986 -0.940 -0.924 0.631
## [433,] -0.579 -0.773 -0.547 -0.369 -0.475 -0.432 -0.417 4.141
## [434,] -0.656 -0.853 3.789 -0.445 -0.552 -0.509 -0.493 -0.332
## [435,] 1.159 -1.370 -1.118 -0.923 -1.039 0.248 4.024 -0.803
## [436,] -0.085 -0.270 -0.055 0.118 0.015 0.056 0.071 0.230
## [437,] -0.406 -0.596 -0.375 -0.201 -0.305 2.369 -0.248 -0.089
## [438,] -0.656 -0.853 -0.624 -0.445 -0.552 4.156 -0.493 -0.332
## [439,] -0.085 -0.270 -0.055 0.118 0.015 0.056 0.071 0.230
## [440,] -0.986 -1.196 5.992 -0.764 -0.876 -0.831 -0.815 -0.647
## [441,] -0.085 -0.270 -0.055 0.118 0.015 0.056 0.071 0.230
## [442,] -1.762 9.520 -1.722 -1.499 -1.631 -1.578 -1.558 -1.363
## [443,] 5.998 -0.775 -1.065 -0.872 -0.986 -0.940 -0.924 -0.753
## [444,] -0.864 -1.068 5.176 -0.646 -0.756 -0.712 -0.696 -0.531
## [445,] -0.085 -0.270 -0.055 0.118 0.015 0.056 0.071 0.230
## [446,] -1.099 -1.314 -1.065 -0.872 -0.986 -0.940 7.392 -0.753
## [447,] -0.986 -1.196 -0.953 -0.764 -0.876 -0.831 6.583 -0.647
## [448,] 5.853 -1.196 -0.953 -0.764 -0.876 -0.831 -0.815 -0.647
## [449,] -1.303 -1.528 -1.266 -1.066 -0.045 -1.137 7.674 -0.942
## [450,] -1.254 -1.477 -1.218 -1.020 8.168 -1.090 -1.073 -0.897
## [451,] -0.406 1.639 -0.375 -0.201 -0.305 -0.263 -0.248 -0.089
## [452,] -0.310 -0.498 -0.279 -0.105 -0.209 1.673 -0.152 0.006
## [453,] -0.085 -0.270 -0.055 0.118 0.015 0.056 0.071 0.230
## [454,] -0.864 -1.068 -0.831 -0.646 -0.756 -0.712 5.703 -0.531
## [455,] -1.396 -1.626 -1.358 -1.154 -1.275 -1.226 9.510 -1.028
## [456,] -1.396 -1.626 -1.358 -1.154 9.144 -1.226 -1.209 -1.028
## [457,] -1.303 -1.528 0.935 -1.066 6.224 -1.137 -1.119 -0.942
## [458,] -1.204 -1.425 7.439 -0.973 -1.089 -1.042 -1.025 -0.851
## [459,] -1.044 -1.256 -1.010 -0.819 -0.932 -0.887 6.995 -0.701
## [460,] -5.379 -5.931 31.422 -4.822 -5.099 -3.055 -4.751 -3.066
## [461,] -0.729 -0.929 -0.697 -0.516 4.526 -0.580 -0.564 -0.402
## [462,] 6.959 0.714 -1.794 -1.568 -0.314 -1.647 -1.627 -1.429
## [463,] -0.579 -0.773 -0.547 -0.369 3.476 -0.432 -0.417 -0.257
## [464,] -0.496 -0.688 -0.464 3.177 -0.393 -0.351 -0.336 -0.177
## [465,] -0.729 3.539 -0.697 -0.516 -0.624 -0.580 -0.564 -0.402
## [466,] -1.567 8.403 -1.529 -1.317 -1.442 -1.391 -1.373 -1.186
## [467,] -1.799 -2.054 -1.758 -1.534 11.918 -1.613 -1.593 -1.396
## [468,] -0.496 -0.688 -0.464 3.177 -0.393 -0.351 -0.336 -0.177
## [469,] -0.579 -0.773 -0.547 -0.369 -0.475 3.602 -0.417 -0.257
## [470,] -0.798 -1.000 -0.765 5.419 -0.691 -0.648 -0.632 -0.468
## [471,] -0.406 1.639 -0.375 -0.201 -0.305 -0.263 -0.248 -0.089
## [472,] -1.153 -1.370 -1.118 -0.923 -1.039 7.691 -0.975 -0.803
## [473,] -0.406 -0.596 -0.375 -0.201 2.273 -0.263 -0.248 -0.089
## [474,] -2.006 -2.276 12.726 -1.728 -1.867 -1.810 -1.790 -1.584
## [475,] -1.303 -1.528 -1.266 -1.066 -1.185 -1.137 -1.119 9.841
## [476,] -0.986 -1.196 -0.953 -0.764 6.315 -0.831 -0.815 -0.647
## [477,] -1.835 -1.291 -0.454 8.655 0.148 -1.647 -1.627 -1.429
## [478,] -2.134 11.649 -2.090 -1.847 -1.990 -1.932 -1.911 -1.699
## [479,] 6.590 -1.314 -1.065 -0.872 -0.986 -0.940 -0.924 -0.753
## [480,] -0.926 -1.134 -0.893 -0.707 5.899 -0.773 -0.756 -0.590
## [481,] 5.591 -3.777 -3.339 11.763 -3.206 -3.128 -3.100 0.050
## [482,] 5.853 -1.196 -0.953 -0.764 -0.876 -0.831 -0.815 -0.647
## [483,] -0.310 -0.498 -0.279 -0.105 -0.209 -0.167 1.702 0.006
## [484,] -0.864 -1.068 -0.831 5.904 -0.756 -0.712 -0.696 -0.531
## [485,] -1.687 9.087 -1.647 -1.429 -1.558 -1.505 -1.487 -1.295
## [486,] -2.006 -2.276 -1.963 -1.728 13.342 -1.810 -1.790 -1.584
## [487,] -1.799 -2.054 -1.758 -1.534 11.918 -1.613 -1.593 -1.396
## [488,] -1.044 -1.256 6.375 -0.819 -0.932 -0.887 -0.870 -0.701
## [489,] -0.729 -0.929 4.277 -0.516 -0.624 -0.580 -0.564 -0.402
## [490,] -0.579 -0.773 -0.547 -0.369 -0.475 -0.432 -0.417 4.141
## [491,] -0.579 -0.773 3.269 -0.369 -0.475 -0.432 -0.417 -0.257
## [492,] 10.886 -2.015 -1.722 -1.499 -1.631 -1.578 -1.558 -1.363
## [493,] 1.517 -0.853 0.111 -0.445 -0.552 -0.509 -0.493 1.363
## [494,] 14.986 -2.697 -2.351 -2.093 -2.246 -2.184 -2.161 -1.936
## [495,] -0.406 -0.596 -0.375 2.514 -0.305 -0.263 -0.248 -0.089
## [496,] 5.853 -1.196 -0.953 -0.764 -0.876 -0.831 -0.815 -0.647
## [497,] 5.052 -1.068 -0.831 -0.646 -0.756 -0.712 -0.696 -0.531
## [498,] -0.656 -0.853 -0.624 -0.445 -0.552 -0.509 4.207 -0.332
## [499,] -1.939 -2.204 -1.897 -1.665 3.983 -1.747 7.429 -1.524
## [500,] -1.484 4.248 2.643 -1.237 -1.361 -1.311 -1.293 -1.109
plot(chi_custA$residuals)
chi_custA$p.value
## [1] 0.0004997501
# Test 3
custA[sample(1:nrow(custA),10),c(2,4)] %>%
chisq.test()
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
##
## Pearson's Chi-squared test
##
## data: .
## X-squared = 10.909, df = 9, p-value = 0.282
custA[sample(1:nrow(custA),10),c(4,6)] %>%
chisq.test()
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
##
## Pearson's Chi-squared test
##
## data: .
## X-squared = 3.36, df = 9, p-value = 0.9483
Since p-value =
chi_custA$p.value, which is less than .05 so we can reject the null hypothesis. So we see there is dependancy in the spending over the quarter.
#Multiple simulation
#Doing multiple check
rm(p_chi)
## Warning in rm(p_chi): object 'p_chi' not found
p_chi <- data.frame(Qt12= rep(0, 50),Qt23= rep(0, 50),Qt34= rep(0, 50))
for(i in 1:50){
chi_test <- custA[sample(1:nrow(custA),10),c(2,4)] %>%
chisq.test()
p_chi$Qt12[i] <- chi_test$p.value
chi_test <- custA[sample(1:nrow(custA),10),c(4,6)] %>%
chisq.test()
p_chi$Qt23[i] <- chi_test$p.value
chi_test <- custA[sample(1:nrow(custA),10),c(6,8)] %>%
chisq.test()
p_chi$Qt34[i] <- chi_test$p.value
# samp <- sample(c("atheist", "non_atheist"), n, replace = TRUE, prob = c(p, 1-p))
# p_hats[i] <- sum(samp == "atheist")/n
}
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
## Warning in chisq.test(.): Chi-squared approximation may be incorrect
# "Chi-squared approximation may be incorrectChi-squared " The warning message found in the solution above is due to the small cell values in the contingency table.
#lets check the key
table(gather(p_chi)$key)
##
## Qt12 Qt23 Qt34
## 50 50 50
#Gather the data so that we can plot on it.
#using geom_jitter to add some noise as most of poits would overlap in normal plot.
gather(p_chi) %>% ggplot(mapping = aes(x= key, y= round(value,3))) + geom_point()+geom_jitter()
gather(p_chi)%>% filter(value > 0.05)
#contigency table
rowSums(custA[,-c(1)])
## [1] 13 16 31 99 9 16 12 44 17 14 22 18 27 29 41 19 21
## [18] 12 33 16 9 39 23 20 31 17 29 14 17 19 26 8 22 15
## [35] 24 42 18 22 17 28 21 29 36 14 17 29 29 44 19 26 14
## [52] 16 12 31 17 42 9 34 26 9 8 27 27 35 15 34 19 11
## [69] 21 24 19 28 9 19 8 23 8 13 11 25 99 8 12 20 33
## [86] 21 41 21 15 26 14 15 164 81 29 11 10 11 19 11 38 23
## [103] 26 11 30 10 30 17 24 17 15 13 17 17 10 18 17 18 36
## [120] 68 14 27 36 14 17 13 8 8 15 28 14 32 16 21 17 38
## [137] 10 12 28 15 15 14 12 8 11 21 13 73 8 11 81 24 32
## [154] 22 18 12 37 13 25 22 8 18 15 47 41 98 8 17 8 22
## [171] 31 19 21 8 21 17 9 23 53 66 37 9 13 32 20 15 14
## [188] 61 13 20 126 58 179 23 24 20 54 23 21 22 27 8 26 14
## [205] 69 13 18 10 22 25 42 160 38 14 27 17 16 27 12 67 47
## [222] 22 48 17 9 51 8 12 41 30 15 28 35 17 20 11 24 13
## [239] 13 26 10 19 15 62 26 65 20 14 20 48 44 26 16 17 37
## [256] 44 17 10 23 46 8 14 17 45 15 19 8 14 9 26 25 25
## [273] 8 23 22 36 20 14 53 21 45 32 20 23 13 9 13 27 15
## [290] 10 17 32 12 19 11 21 28 43 11 48 14 25 28 15 14 12
## [307] 12 20 11 39 16 22 42 32 21 20 42 20 10 26 30 17 12
## [324] 28 13 40 35 43 34 59 24 25 10 15 29 31 16 36 16 13
## [341] 12 28 21 21 24 38 12 17 10 19 13 12 21 32 12 13 34
## [358] 10 47 37 32 14 24 13 47 17 11 26 29 31 19 20 22 58
## [375] 17 19 17 36 34 12 9 9 35 23 8 16 35 25 121 23 22
## [392] 30 44 13 33 10 23 37 19 15 20 18 28 59 12 31 17 12
## [409] 12 35 27 19 13 22 8 19 12 16 15 16 54 27 25 13 13
## [426] 46 13 9 25 16 22 8 17 35 13 13 50 23 17 25 15 47
## [443] 27 20 27 16 14 87 24 39 14 16 13 26 38 38 13 17 21
## [460] 21 13 62 32 32 17 91 34 30 37 23 20 28 17 12 24 26
## [477] 8 15 36 14 10 55 11 16 53 17 67 8 36 10 20 13 41
## [494] 24 22 21 81 20 23 39 16 26 18 22 26 38 9 9 10 27
## [511] 22 38 25 14 32 18 20 163 11 46 56 14 20 8 13 10 48
## [528] 13 55 10 26 13 61 20 12 94 21 31 19 37 9 10 10 22
## [545] 41 15 28 27 18 8 37 30 13 37 39 20 32 22 26 12 44
## [562] 14 27 18 11 28 13 18 21 146 34 9 20 15 11 11 19 15
## [579] 26 41 34 19 23 26 8 26 21 14 12 37 42 20 25 29 22
## [596] 13 26 29 12 27 11 33 17 15 35 22 8 18 25 18 19 13
## [613] 19 10 24 19 57 75 17 12 37 12 18 12 41 21 74 41 17
## [630] 21 21 27 14 16 31 27 10 20 11 28 31 9 79 15 25 37
## [647] 8 20 32 25 18 8 13 16 21 97 47 31 27 15 12 49 13
## [664] 23 16 11 33 37 27 9 12 30 40 11 11 20 12 12 19 49
## [681] 8 14 38 17 19 16 15 43 15 37 18 17 10 14 46 31 120
## [698] 10 35 43 17 24 14 27 54 35 26 19 35 19 27 33 26 17
## [715] 18 13 65 8 17 35 8 10 23 13 33 11 9 16 17 27 32
## [732] 15 16 11 41 47 17 22 22 13 20 17 9 11 22 13 63 25
## [749] 717 27 8 8 60 18 32 24 24 23 18 20 25 22 11 15 13
## [766] 27 47 8 10 32 25 13 27 16 14 28 8 15 15 11 12 35
## [783] 14 14 30 9 33 17 12 13 20 24 95 27 78 21 31 24 10
## [800] 25 19 21 27 13 12 47 35 16 17 8 39 30 38 20 10 17
## [817] 19 16 10 27 23 27 12 15 28 16 68 25 9 12 33 19 20
## [834] 33 37 14 10 22 22 19 25 227 19 22 52 14 13 9 12 16
## [851] 17 12 11 27 11 32 33 15 31 15 37 8 9 17 61 13 11
## [868] 21 18 13 14 93 8 122 19 19 19 13 14 14 31 37 8 62
## [885] 36 21 14 28 94 11 26 13 22 15 33 19 10 27 12 19 11
## [902] 9 31 15 29 120 14 17 23 32 17 31 29 23 13 40 9 31
## [919] 26 14 10 19 21 9 16 18 19 14 17 13 114 20 43 13 18
## [936] 13 19 16 35 13 22 8 26 17 14 16 17 21 12 12 22 32
## [953] 27 23 8 20 16 8 8 15 35 31 18 16 25 9 12 13 8
## [970] 39 8 13 19 24 17 20 32 19 20 22 20 20 18 25 34 12
## [987] 51 17 19 13 17 20 11 18 27 9 27 8 18 12
colSums(custA[,-c(1)])
## Q1_17 Q1_18 Q2_17 Q2_18 Q3_17 Q3_18 Q4_17 Q4_18
## 3438 3399 3660 3143 3388 2911 2841 2870
Answer to Business Question A: Does customer who baught more at the Quarter end , how did they perfrom during the followin quarter.
Since p-value =
chi_custA$p.value, which is less than .05 so we can reject the null hypothesis. So we see there is dependancy in the spending over the quarter. Multiple simulation also indicatess pvlaue < 0.05 , for Aplha = 0.5 it indicates that we are 95% confident that spending over each quater is depended on spending over last quarter.
Limitation : We can’t evalaute spending is more or less using Chi-square test , as it is goodness of fittest only.
Lets evaluate Promotion and qty realtion Qt.
# Creating subset of data
lm_cust <- mkt_Datalean[,c(15,4,1,3,5,7,11,12,13,14)]
lm_cust<- rename(lm_cust , promo = `External Description` )
lm_cust$KUNNR_NEW = as.character(lm_cust$KUNNR_NEW)
lm_cust$Brand = as.factor(lm_cust$Brand)
lm_cust$zip = as.factor(lm_cust$zip)
lm_cust$city = as.factor(lm_cust$city)
lm_cust$state = as.factor(lm_cust$state)
lm_cust$Qt = as.factor(lm_cust$Qt)
# Check data
head(lm_cust)
summary(lm_cust)
## KUNNR_NEW Order Quantity Brand
## Length:5000 Min. : 1.00 RB : 752
## Class :character 1st Qu.: 5.00 RX : 713
## Mode :character Median : 10.00 OO : 357
## Mean : 14.68 OX : 346
## 3rd Qu.: 18.00 RY : 304
## Max. :690.00 HC : 286
## (Other):2242
## Order Date Promotion Order Doll promo
## Min. :2017-01-03 00:00:00 Min. : 0.0 Length:5000
## 1st Qu.:2017-06-29 00:00:00 1st Qu.: 343.9 Class :character
## Median :2018-01-17 00:00:00 Median : 737.1 Mode :character
## Mean :2017-12-31 19:47:42 Mean : 1102.9
## 3rd Qu.:2018-06-22 00:00:00 3rd Qu.: 1367.1
## Max. :2018-12-29 00:00:00 Max. :41197.7
##
## city state zip Qt
## HOUSTON : 88 CA :1003 92683 : 18 Q1_18 : 730
## BROOKLYN : 53 TX : 581 77494 : 12 Q2_18 : 688
## LOS ANGELES: 51 NY : 363 33131 : 11 Q1_17 : 671
## MIAMI : 49 FL : 282 90006 : 11 Q3_18 : 627
## LAS VEGAS : 37 PA : 181 33901 : 10 Q3_17 : 607
## SAN DIEGO : 37 (Other):2580 (Other):4937 Q2_17 : 587
## (Other) :4685 NA's : 10 NA's : 1 (Other):1090
# lm_cust[which(is.na(lm_cust$state)),]
lm_cust <- lm_cust %>% group_by(KUNNR_NEW,Qt,Brand,`Order Date`,promo,city,state) %>% summarise(Order_Qty = sum(`Order Quantity`),Doll_Val = sum(`Promotion Order Doll`))
## Warning: Factor `state` contains implicit NA, consider using
## `forcats::fct_explicit_na`
#
# lm_cust[which(lm_cust$Brand=="OO"),] %>% ggplot(mapping = aes(x= promo, y= Order_Qty,group= Qt , color = Qt)) + geom_line()+
# geom_point() + geom_jitter()+ facet_grid(year(`Order Date`)~ .)
#
# ggplot(lm_cust,mapping = aes(x= Qt, y= Order_Qty, group= Brand ,color= Brand )) + geom_line()+
# geom_point() + geom_jitter()
# Brand by Year
lm_cust[which(lm_cust$Brand %in% c("RB","RJ")),] %>% group_by(promo,Brand,Qt,year =year(`Order Date`)) %>%summarise(Order_Qty = sum(Order_Qty)) %>%
ggplot(mapping = aes(x=Brand, y = Order_Qty,fill = Qt)) +
geom_col()+facet_grid(year~ .)+
theme(axis.text.x = element_text(angle = 70, hjust = 1)) +
scale_y_continuous( labels = scales::number)+
ggtitle("Brand by Year ") +ylab("Ordered Unit")
# promo by year and Brand
plotly::ggplotly( lm_cust[which(lm_cust$Brand %in% c("RB")),] %>% group_by(promo,Brand,Qt,year =year(`Order Date`)) %>%summarise(Order_Qty = sum(Order_Qty)) %>%
ggplot(mapping = aes(x=promo, y = Order_Qty,fill = Qt)) +
geom_col( position = "dodge")+facet_grid(Brand+year~ .,scales="free")+
theme(axis.text.x = element_text(angle = 70, hjust = 1)) +
scale_y_continuous( labels = scales::number)+
ggtitle("Promo by year and Brand ") +ylab("Ordered Unit"))
#Plotly check
plotData <- lm_cust[which(lm_cust$Brand %in% c("RB")),] %>% group_by(promo,Brand,Qt,month =month(`Order Date`)) %>%summarise(Order_Qty = sum(Order_Qty))
plot_ly(x = plotData$promo, y = plotData$Order_Qty, mode= "marker", type = "bar", data= plotData, color= plotData$Qt) %>% layout(title="RB Brand Order ")
## Warning: 'bar' objects don't have these attributes: 'mode'
## Valid attributes include:
## 'type', 'visible', 'showlegend', 'legendgroup', 'opacity', 'name', 'uid', 'ids', 'customdata', 'selectedpoints', 'hoverinfo', 'hoverlabel', 'stream', 'transforms', 'uirevision', 'x', 'x0', 'dx', 'y', 'y0', 'dy', 'text', 'hovertext', 'hovertemplate', 'textposition', 'textfont', 'insidetextfont', 'outsidetextfont', 'constraintext', 'cliponaxis', 'orientation', 'base', 'offset', 'width', 'marker', 'offsetgroup', 'alignmentgroup', 'selected', 'unselected', 'r', 't', '_deprecated', 'error_x', 'error_y', 'xcalendar', 'ycalendar', 'xaxis', 'yaxis', 'idssrc', 'customdatasrc', 'hoverinfosrc', 'xsrc', 'ysrc', 'textsrc', 'hovertextsrc', 'hovertemplatesrc', 'textpositionsrc', 'basesrc', 'offsetsrc', 'widthsrc', 'rsrc', 'tsrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'bar' objects don't have these attributes: 'mode'
## Valid attributes include:
## 'type', 'visible', 'showlegend', 'legendgroup', 'opacity', 'name', 'uid', 'ids', 'customdata', 'selectedpoints', 'hoverinfo', 'hoverlabel', 'stream', 'transforms', 'uirevision', 'x', 'x0', 'dx', 'y', 'y0', 'dy', 'text', 'hovertext', 'hovertemplate', 'textposition', 'textfont', 'insidetextfont', 'outsidetextfont', 'constraintext', 'cliponaxis', 'orientation', 'base', 'offset', 'width', 'marker', 'offsetgroup', 'alignmentgroup', 'selected', 'unselected', 'r', 't', '_deprecated', 'error_x', 'error_y', 'xcalendar', 'ycalendar', 'xaxis', 'yaxis', 'idssrc', 'customdatasrc', 'hoverinfosrc', 'xsrc', 'ysrc', 'textsrc', 'hovertextsrc', 'hovertemplatesrc', 'textpositionsrc', 'basesrc', 'offsetsrc', 'widthsrc', 'rsrc', 'tsrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'bar' objects don't have these attributes: 'mode'
## Valid attributes include:
## 'type', 'visible', 'showlegend', 'legendgroup', 'opacity', 'name', 'uid', 'ids', 'customdata', 'selectedpoints', 'hoverinfo', 'hoverlabel', 'stream', 'transforms', 'uirevision', 'x', 'x0', 'dx', 'y', 'y0', 'dy', 'text', 'hovertext', 'hovertemplate', 'textposition', 'textfont', 'insidetextfont', 'outsidetextfont', 'constraintext', 'cliponaxis', 'orientation', 'base', 'offset', 'width', 'marker', 'offsetgroup', 'alignmentgroup', 'selected', 'unselected', 'r', 't', '_deprecated', 'error_x', 'error_y', 'xcalendar', 'ycalendar', 'xaxis', 'yaxis', 'idssrc', 'customdatasrc', 'hoverinfosrc', 'xsrc', 'ysrc', 'textsrc', 'hovertextsrc', 'hovertemplatesrc', 'textpositionsrc', 'basesrc', 'offsetsrc', 'widthsrc', 'rsrc', 'tsrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'bar' objects don't have these attributes: 'mode'
## Valid attributes include:
## 'type', 'visible', 'showlegend', 'legendgroup', 'opacity', 'name', 'uid', 'ids', 'customdata', 'selectedpoints', 'hoverinfo', 'hoverlabel', 'stream', 'transforms', 'uirevision', 'x', 'x0', 'dx', 'y', 'y0', 'dy', 'text', 'hovertext', 'hovertemplate', 'textposition', 'textfont', 'insidetextfont', 'outsidetextfont', 'constraintext', 'cliponaxis', 'orientation', 'base', 'offset', 'width', 'marker', 'offsetgroup', 'alignmentgroup', 'selected', 'unselected', 'r', 't', '_deprecated', 'error_x', 'error_y', 'xcalendar', 'ycalendar', 'xaxis', 'yaxis', 'idssrc', 'customdatasrc', 'hoverinfosrc', 'xsrc', 'ysrc', 'textsrc', 'hovertextsrc', 'hovertemplatesrc', 'textpositionsrc', 'basesrc', 'offsetsrc', 'widthsrc', 'rsrc', 'tsrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'bar' objects don't have these attributes: 'mode'
## Valid attributes include:
## 'type', 'visible', 'showlegend', 'legendgroup', 'opacity', 'name', 'uid', 'ids', 'customdata', 'selectedpoints', 'hoverinfo', 'hoverlabel', 'stream', 'transforms', 'uirevision', 'x', 'x0', 'dx', 'y', 'y0', 'dy', 'text', 'hovertext', 'hovertemplate', 'textposition', 'textfont', 'insidetextfont', 'outsidetextfont', 'constraintext', 'cliponaxis', 'orientation', 'base', 'offset', 'width', 'marker', 'offsetgroup', 'alignmentgroup', 'selected', 'unselected', 'r', 't', '_deprecated', 'error_x', 'error_y', 'xcalendar', 'ycalendar', 'xaxis', 'yaxis', 'idssrc', 'customdatasrc', 'hoverinfosrc', 'xsrc', 'ysrc', 'textsrc', 'hovertextsrc', 'hovertemplatesrc', 'textpositionsrc', 'basesrc', 'offsetsrc', 'widthsrc', 'rsrc', 'tsrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'bar' objects don't have these attributes: 'mode'
## Valid attributes include:
## 'type', 'visible', 'showlegend', 'legendgroup', 'opacity', 'name', 'uid', 'ids', 'customdata', 'selectedpoints', 'hoverinfo', 'hoverlabel', 'stream', 'transforms', 'uirevision', 'x', 'x0', 'dx', 'y', 'y0', 'dy', 'text', 'hovertext', 'hovertemplate', 'textposition', 'textfont', 'insidetextfont', 'outsidetextfont', 'constraintext', 'cliponaxis', 'orientation', 'base', 'offset', 'width', 'marker', 'offsetgroup', 'alignmentgroup', 'selected', 'unselected', 'r', 't', '_deprecated', 'error_x', 'error_y', 'xcalendar', 'ycalendar', 'xaxis', 'yaxis', 'idssrc', 'customdatasrc', 'hoverinfosrc', 'xsrc', 'ysrc', 'textsrc', 'hovertextsrc', 'hovertemplatesrc', 'textpositionsrc', 'basesrc', 'offsetsrc', 'widthsrc', 'rsrc', 'tsrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'bar' objects don't have these attributes: 'mode'
## Valid attributes include:
## 'type', 'visible', 'showlegend', 'legendgroup', 'opacity', 'name', 'uid', 'ids', 'customdata', 'selectedpoints', 'hoverinfo', 'hoverlabel', 'stream', 'transforms', 'uirevision', 'x', 'x0', 'dx', 'y', 'y0', 'dy', 'text', 'hovertext', 'hovertemplate', 'textposition', 'textfont', 'insidetextfont', 'outsidetextfont', 'constraintext', 'cliponaxis', 'orientation', 'base', 'offset', 'width', 'marker', 'offsetgroup', 'alignmentgroup', 'selected', 'unselected', 'r', 't', '_deprecated', 'error_x', 'error_y', 'xcalendar', 'ycalendar', 'xaxis', 'yaxis', 'idssrc', 'customdatasrc', 'hoverinfosrc', 'xsrc', 'ysrc', 'textsrc', 'hovertextsrc', 'hovertemplatesrc', 'textpositionsrc', 'basesrc', 'offsetsrc', 'widthsrc', 'rsrc', 'tsrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'bar' objects don't have these attributes: 'mode'
## Valid attributes include:
## 'type', 'visible', 'showlegend', 'legendgroup', 'opacity', 'name', 'uid', 'ids', 'customdata', 'selectedpoints', 'hoverinfo', 'hoverlabel', 'stream', 'transforms', 'uirevision', 'x', 'x0', 'dx', 'y', 'y0', 'dy', 'text', 'hovertext', 'hovertemplate', 'textposition', 'textfont', 'insidetextfont', 'outsidetextfont', 'constraintext', 'cliponaxis', 'orientation', 'base', 'offset', 'width', 'marker', 'offsetgroup', 'alignmentgroup', 'selected', 'unselected', 'r', 't', '_deprecated', 'error_x', 'error_y', 'xcalendar', 'ycalendar', 'xaxis', 'yaxis', 'idssrc', 'customdatasrc', 'hoverinfosrc', 'xsrc', 'ysrc', 'textsrc', 'hovertextsrc', 'hovertemplatesrc', 'textpositionsrc', 'basesrc', 'offsetsrc', 'widthsrc', 'rsrc', 'tsrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
lm_cust[which(lm_cust$Brand %in% c("RB")),] %>% group_by(promo,Brand,Qt,month =month(`Order Date`)) %>%summarise(Order_Qty = sum(Order_Qty))
linPlot <- lm_cust[which(lm_cust$Brand %in% c("RB","OO")),] %>% group_by(Brand,date = month(`Order Date`) )%>%summarise(OrderQty = sum(Order_Qty))
linPlot <- lm_cust[which(lm_cust$Brand %in% c("RB","OO")),] %>% group_by(Brand,date = (format(`Order Date`, "%Y-%m")) )%>%summarise(OrderQty = sum(Order_Qty))
linPlot <- lm_cust[which(lm_cust$Brand %in% c("RB","OO")),] %>% group_by(Brand,date = (month(`Order Date`)) , year = year(`Order Date`))%>%summarise(OrderQty = sum(Order_Qty))
plot_ly(x= linPlot$date,y= linPlot$OrderQty, color = as.factor(linPlot$Brand) , data = linPlot[which(linPlot$year==2017),], linetype = I("Brand"))
## Warning: The following are not valid linetype codes:
## 'Brand'
## Valid linetypes include:
## 'solid', 'dot', 'dash', 'longdash', 'dashdot', 'longdashdot'
## Warning: The following are not valid linetype codes:
## 'Brand'
## Valid linetypes include:
## 'solid', 'dot', 'dash', 'longdash', 'dashdot', 'longdashdot'
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
linPlot$year <- as.factor(linPlot$year)
plot_ly(x= linPlot$date,y= linPlot$OrderQty, color = as.factor(linPlot$year) , data = linPlot[which(linPlot$brand=="RB"),], linetype = "solid")
## Warning: Unknown or uninitialised column: 'brand'.
## Warning: Factor `Brand` contains implicit NA, consider using
## `forcats::fct_explicit_na`
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels
# linPlot <- lm_cust[which(lm_cust$Brand %in% c("RB","OO","TY")),] %>% group_by(Brand,dateL = `Order Date`)%>%summarise(OrderQty = sum(Order_Qty))
# plot_ly(data= linPlot,x= month(linPlot$dateL), y = linPlot$OrderQty,color = linPlot$Brand , linetype = 'dot' )
# str_replace(str_extract(linPlot$dateL[1],"\\d+_\\d{2}"),"_","")
linPlot <- lm_cust[which(lm_cust$Brand %in% c("RB","OO","TY")),] %>% group_by(Brand,
dateL = Qt
)%>%summarise(OrderQty = sum(Order_Qty))
linPlot$Qt <- as.numeric(str_replace_all(str_extract_all(linPlot$dateL,"\\d+_\\d{2}"),"_",""))
plot_ly(data= linPlot,x= linPlot$Qt, y = linPlot$OrderQty,color = linPlot$Brand , linetype = 'dot' ) %>% layout(title = " Sales by Brand by Quarter")
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
# check if all promotions are running every year
head(table(year(lm_cust$`Order Date`),lm_cust$promo))
##
## ANB B2B200 CHANEL PRE CHROME8 CODE F H15 HC18 LUX40 MVE150 MVENB
## 2017 1 3 3 2 18 240 7 278 1 1
## 2018 0 0 0 0 0 0 0 0 0 0
##
## NASC150 NASC75 NB NB20 NB40 OO15 OOX40 OOX60 Other OY12 PB1 PB3
## 2017 19 15 14 3 1 2 26 5 757 20 7 2
## 2018 0 0 0 0 0 0 0 0 1943 0 0 0
##
## PERSOL PRE PRE-SELL B PRE-SELL T PRE-SELL V PRE SELL T RB15 RSD
## 2017 2 1 4 3 7 21 6
## 2018 0 0 0 0 0 0 8
##
## SUN1 SUN2 SY1 SY100 SY1000 SY2 SY200 SY250 SY5 SYNERGY54 SYVE
## 2017 6 9 0 341 0 0 66 7 0 0 0
## 2018 0 0 242 0 23 33 0 106 34 25 90
##
## TSO20 UP1 UP3 VIP VP1200 VPFP150 VPFP200 VPNB VSE20 WC1 WC2
## 2017 2 227 119 0 11 8 51 7 1 73 2
## 2018 0 0 0 28 0 0 0 0 0 24 3
##
## Wild Card
## 2017 0
## 2018 39
Try Predicting Quantity based on Known informaiton . Identifying Best model to predict Quantity
# pairs.panels(lm_cust[,c(2,3)])
# Try Predicting Quantity based on Known informaiton .
# Identifying Best model to predict Quantity
head(lm_cust)
result <- data.frame(var = 1:10,pval = 1:10, comment=1:10)
result$var <- "A"
result$pval <- "A"
result$comment <- "A"
# Working With Sample
set.seed(42672)
lm_cust_s1 <- lm_cust[sample(nrow(lm_cust),200),]
lm_cust_s1$month <- month(lm_cust_s1$`Order Date`)
lm_cust_s1$month <- as.factor(lm_cust_s1$month )
names(lm_cust_s1)
## [1] "KUNNR_NEW" "Qt" "Brand" "Order Date" "promo"
## [6] "city" "state" "Order_Qty" "Doll_Val" "month"
lm1 <- lm(Order_Qty ~ Qt + Brand + promo + month + state,lm_cust_s1)
summary(lm1)
##
## Call:
## lm(formula = Order_Qty ~ Qt + Brand + promo + month + state,
## data = lm_cust_s1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -35.673 -4.231 0.000 2.601 51.050
##
## Coefficients: (4 not defined because of singularities)
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -36.46504 23.40782 -1.558 0.1227
## QtQ1_18 18.00039 24.29936 0.741 0.4607
## QtQ2_17 18.37125 9.28988 1.978 0.0510 .
## QtQ2_18 20.93323 23.58605 0.888 0.3771
## QtQ3_17 22.31441 25.94766 0.860 0.3920
## QtQ3_18 23.13547 25.00954 0.925 0.3574
## QtQ4_17 20.79028 25.63396 0.811 0.4194
## QtQ4_18 25.55953 25.53385 1.001 0.3194
## BrandAX -2.22291 16.43417 -0.135 0.8927
## BrandBB 18.17065 20.39375 0.891 0.3753
## BrandBE 11.38307 15.89782 0.716 0.4758
## BrandBV 13.25507 19.94719 0.665 0.5080
## BrandDG 22.90699 13.35774 1.715 0.0897 .
## BrandEA 17.22271 15.04887 1.144 0.2554
## BrandHC 37.07761 13.91419 2.665 0.0091 **
## BrandMK 18.92319 13.77854 1.373 0.1730
## BrandMU -8.49975 27.25828 -0.312 0.7559
## BrandOJ 10.34942 16.85203 0.614 0.5406
## BrandOO 19.00698 12.96248 1.466 0.1460
## BrandOX 28.20339 13.14453 2.146 0.0345 *
## BrandOY 13.88347 14.51767 0.956 0.3414
## BrandPH 20.20884 14.28289 1.415 0.1605
## BrandPO 32.50025 18.97884 1.712 0.0902 .
## BrandPR 30.68086 13.46828 2.278 0.0250 *
## BrandPS 15.15263 15.71143 0.964 0.3374
## BrandRA 12.86219 13.64030 0.943 0.3482
## BrandRB 21.61683 12.22194 1.769 0.0803 .
## BrandRJ 10.98168 16.90526 0.650 0.5176
## BrandRL 18.91419 14.70578 1.286 0.2016
## BrandRX 27.52025 12.74336 2.160 0.0334 *
## BrandRY 9.72803 11.97928 0.812 0.4188
## BrandSF -19.48943 20.06241 -0.971 0.3339
## BrandTF 27.51580 14.93427 1.842 0.0686 .
## BrandTY 10.20080 18.39706 0.554 0.5806
## BrandVE 19.25721 13.07980 1.472 0.1444
## BrandVO 15.23984 17.08040 0.892 0.3746
## promoH15 -1.62030 15.93106 -0.102 0.9192
## promoLUX40 11.75592 17.30055 0.680 0.4985
## promoNASC75 19.41953 23.00442 0.844 0.4008
## promoNB 12.57707 19.19284 0.655 0.5139
## promoOOX40 8.29981 20.65580 0.402 0.6888
## promoOther -8.26783 28.79134 -0.287 0.7746
## promoOY12 25.30624 23.55245 1.074 0.2854
## promoPB1 36.87749 29.68013 1.242 0.2172
## promoRB15 32.57282 23.85811 1.365 0.1755
## promoRSD 19.17100 39.07783 0.491 0.6249
## promoSUN2 15.54299 26.06557 0.596 0.5524
## promoSY1 -1.34877 29.26186 -0.046 0.9633
## promoSY100 -4.94784 29.50864 -0.168 0.8672
## promoSY1000 -11.99035 34.35517 -0.349 0.7279
## promoSY2 0.40351 31.32019 0.013 0.9897
## promoSY200 18.21825 20.17638 0.903 0.3689
## promoSY250 25.08751 30.41952 0.825 0.4117
## promoSY5 11.36126 34.55088 0.329 0.7430
## promoSYVE -4.38441 31.90636 -0.137 0.8910
## promoUP1 -2.14988 16.43054 -0.131 0.8962
## promoUP3 -2.70304 17.76997 -0.152 0.8794
## promoVIP 9.09819 32.99633 0.276 0.7834
## promoVPNB 10.38062 20.70836 0.501 0.6174
## promoWC1 18.58697 18.86336 0.985 0.3270
## promoWC2 5.27787 24.31924 0.217 0.8287
## promoWild Card 1.73126 33.96237 0.051 0.9595
## month2 16.65961 6.60551 2.522 0.0134 *
## month3 15.88870 7.07670 2.245 0.0272 *
## month4 -0.37627 6.58180 -0.057 0.9545
## month5 -2.09586 7.83357 -0.268 0.7896
## month6 NA NA NA NA
## month7 3.19081 6.74421 0.473 0.6372
## month8 -1.95339 5.84180 -0.334 0.7389
## month9 NA NA NA NA
## month10 -4.94403 7.30411 -0.677 0.5002
## month11 -0.06341 7.12405 -0.009 0.9929
## month12 NA NA NA NA
## stateAZ 16.48838 20.33711 0.811 0.4196
## stateCA 12.05055 11.67329 1.032 0.3046
## stateCO 16.86173 13.42809 1.256 0.2124
## stateCT 9.25895 13.85852 0.668 0.5057
## stateFL 17.80283 12.36884 1.439 0.1535
## stateGA 8.42038 13.33407 0.631 0.5293
## stateIA 42.20359 18.67097 2.260 0.0262 *
## stateID 7.79968 15.68725 0.497 0.6202
## stateIL 7.97249 12.61030 0.632 0.5288
## stateIN 2.27695 13.43487 0.169 0.8658
## stateKS 0.64039 17.64006 0.036 0.9711
## stateKY 7.61863 13.25988 0.575 0.5670
## stateLA 20.35612 16.98149 1.199 0.2337
## stateMA 16.30341 13.31618 1.224 0.2240
## stateMD 10.18281 19.31153 0.527 0.5993
## stateME 5.98689 17.51323 0.342 0.7332
## stateMI 15.33782 14.10445 1.087 0.2797
## stateMO 8.71079 13.97244 0.623 0.5345
## stateMS 12.04992 16.12025 0.748 0.4567
## stateNC 0.85877 14.63154 0.059 0.9533
## stateNE 11.05145 15.70960 0.703 0.4835
## stateNH 14.09508 15.65536 0.900 0.3703
## stateNJ 7.86700 14.03057 0.561 0.5764
## stateNM 5.39523 16.00708 0.337 0.7368
## stateNV 17.62102 14.53551 1.212 0.2285
## stateNY 15.54457 12.17271 1.277 0.2048
## stateOH 9.27533 13.50044 0.687 0.4938
## stateOK 9.83495 13.88873 0.708 0.4807
## stateOR -5.41943 22.72746 -0.238 0.8121
## statePA 9.97787 12.64259 0.789 0.4320
## statePR 15.88840 14.82491 1.072 0.2866
## stateRI NA NA NA NA
## stateTN 12.86440 16.19163 0.795 0.4289
## stateTX 10.79331 11.72175 0.921 0.3596
## stateUT 11.65310 19.84770 0.587 0.5586
## stateVA 18.44788 19.48008 0.947 0.3461
## stateWA 19.71919 16.14748 1.221 0.2251
## stateWI 7.38835 16.26748 0.454 0.6508
## stateWV 27.63151 21.56170 1.282 0.2032
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 13.84 on 92 degrees of freedom
## Multiple R-squared: 0.5322, Adjusted R-squared: -0.01177
## F-statistic: 0.9784 on 107 and 92 DF, p-value: 0.5452
anova(lm1)
result$var[1] <- "lm(formula = Order_Qty ~ Qt + Brand + promo + month + state,
data = lm_cust_s1)"
result$pval[1] <- "Adjusted R-squared: 0.2356 F-statistic: 1.568 on 108 and 91 DF, p-value: 0.01388"
result$comment[1] <- "(Month , State ) Qt,Promo codes are significant,state is not "
#Dropping State
lm2 <- lm(Order_Qty ~ Qt + Brand + promo + month,lm_cust_s1)
summary(lm2)
##
## Call:
## lm(formula = Order_Qty ~ Qt + Brand + promo + month, data = lm_cust_s1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -36.383 -5.780 0.000 3.595 53.573
##
## Coefficients: (3 not defined because of singularities)
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -12.49704 14.63275 -0.854 0.39465
## QtQ1_18 12.18308 18.91116 0.644 0.52056
## QtQ2_17 8.30689 6.61006 1.257 0.21111
## QtQ2_18 11.99134 18.66270 0.643 0.52166
## QtQ3_17 16.32355 19.88174 0.821 0.41313
## QtQ3_18 15.75627 19.51636 0.807 0.42095
## QtQ4_17 13.88639 19.94766 0.696 0.48758
## QtQ4_18 20.44311 19.83325 1.031 0.30457
## BrandAX -5.90175 13.84548 -0.426 0.67062
## BrandBB 16.40336 17.22325 0.952 0.34266
## BrandBE 5.53851 13.56604 0.408 0.68375
## BrandBV 12.67011 16.80670 0.754 0.45229
## BrandDG 18.89818 11.38464 1.660 0.09933 .
## BrandEA 12.65017 12.85487 0.984 0.32691
## BrandHC 35.90515 11.85869 3.028 0.00297 **
## BrandMK 10.29752 11.62513 0.886 0.37736
## BrandMU -14.39136 24.54561 -0.586 0.55868
## BrandOJ 3.69422 14.05848 0.263 0.79314
## BrandOO 14.84016 10.86683 1.366 0.17441
## BrandOX 20.89679 10.90196 1.917 0.05746 .
## BrandOY 9.65762 11.69246 0.826 0.41033
## BrandPH 12.84702 11.53395 1.114 0.26740
## BrandPO 26.60864 16.77271 1.586 0.11507
## BrandPR 25.24977 11.56601 2.183 0.03082 *
## BrandPS 11.41966 12.97302 0.880 0.38034
## BrandRA 8.67947 11.75566 0.738 0.46165
## BrandRB 17.81507 10.35035 1.721 0.08759 .
## BrandRJ 3.51047 13.87317 0.253 0.80064
## BrandRL 10.99017 11.89269 0.924 0.35714
## BrandRX 22.17050 10.74071 2.064 0.04099 *
## BrandRY 7.47817 10.44905 0.716 0.47547
## BrandSF -19.53713 16.67908 -1.171 0.24360
## BrandTF 21.66324 12.40692 1.746 0.08316 .
## BrandTY 11.08892 14.15169 0.784 0.43471
## BrandVE 13.83746 10.79166 1.282 0.20204
## BrandVO 5.97036 12.74835 0.468 0.64034
## promoH15 0.47269 11.02617 0.043 0.96587
## promoLUX40 10.53215 10.74763 0.980 0.32893
## promoNASC75 21.05516 17.12019 1.230 0.22098
## promoNB 5.83877 13.24998 0.441 0.66019
## promoOOX40 8.42342 12.50389 0.674 0.50172
## promoOther -7.16441 21.25078 -0.337 0.73656
## promoOY12 14.83942 17.22027 0.862 0.39042
## promoPB1 11.65687 16.34348 0.713 0.47697
## promoRB15 20.31504 16.93654 1.199 0.23252
## promoRSD 5.31312 25.89650 0.205 0.83776
## promoSUN2 19.58150 20.90827 0.937 0.35073
## promoSY1 -3.99612 21.60869 -0.185 0.85357
## promoSY100 -5.12616 21.83491 -0.235 0.81476
## promoSY1000 -6.65029 25.74083 -0.258 0.79654
## promoSY2 2.06180 23.17502 0.089 0.92925
## promoSY200 15.45106 14.45747 1.069 0.28717
## promoSY250 23.85974 22.71510 1.050 0.29549
## promoSY5 8.27890 26.27859 0.315 0.75323
## promoSYVE -5.37083 25.18542 -0.213 0.83146
## promoUP1 -4.34772 10.49617 -0.414 0.67940
## promoUP3 -5.97238 11.28390 -0.529 0.59751
## promoVIP 11.96719 26.11733 0.458 0.64757
## promoVPNB 6.11156 15.05503 0.406 0.68545
## promoWC1 13.86758 12.70899 1.091 0.27722
## promoWC2 9.60890 16.68194 0.576 0.56561
## promoWild Card -4.55881 24.69039 -0.185 0.85380
## month2 13.06606 5.17905 2.523 0.01285 *
## month3 8.99134 5.20897 1.726 0.08670 .
## month4 0.29752 4.88696 0.061 0.95155
## month5 0.06004 5.99863 0.010 0.99203
## month6 NA NA NA NA
## month7 3.22993 5.69877 0.567 0.57184
## month8 -1.70347 4.70572 -0.362 0.71794
## month9 NA NA NA NA
## month10 -6.88822 5.86657 -1.174 0.24248
## month11 -2.75016 5.60855 -0.490 0.62471
## month12 NA NA NA NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 12.67 on 130 degrees of freedom
## Multiple R-squared: 0.4455, Adjusted R-squared: 0.1512
## F-statistic: 1.514 on 69 and 130 DF, p-value: 0.0217
anova(lm2)
result$var[2] <- "lm(formula = Order_Qty ~ Qt + Brand + promo + month, data = lm_cust_s1)"
result$pval[2] <- "Adjusted R-squared: 0.3198 F-statistic: 2.396 on 67 and 132 DF, p-value: 9.788e-06"
result$comment[2] <- "(Month)Brand is not significant"
#Promo promoVPFP200 turns out to more significant here.
#3 Dropping brand info
lm3 <- lm(Order_Qty ~ Qt + promo + month,lm_cust_s1)
summary(lm3)
##
## Call:
## lm(formula = Order_Qty ~ Qt + promo + month, data = lm_cust_s1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -25.602 -6.340 -1.794 3.365 71.781
##
## Coefficients: (3 not defined because of singularities)
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.3586 10.1164 0.431 0.6672
## QtQ1_18 9.0901 20.0945 0.452 0.6516
## QtQ2_17 2.2828 6.3014 0.362 0.7176
## QtQ2_18 6.3740 19.8318 0.321 0.7483
## QtQ3_17 7.4515 20.8205 0.358 0.7209
## QtQ3_18 8.8989 20.6177 0.432 0.6666
## QtQ4_17 7.2990 20.8614 0.350 0.7269
## QtQ4_18 13.9049 20.9071 0.665 0.5070
## promoH15 5.6875 11.3996 0.499 0.6185
## promoLUX40 12.1038 10.7129 1.130 0.2603
## promoNASC75 24.2221 17.3681 1.395 0.1651
## promoNB 1.9544 13.8675 0.141 0.8881
## promoOOX40 16.2523 12.8856 1.261 0.2091
## promoOther 0.1734 22.4412 0.008 0.9938
## promoOY12 7.6414 16.9461 0.451 0.6527
## promoPB1 9.6414 16.9461 0.569 0.5702
## promoRB15 28.7633 17.6668 1.628 0.1055
## promoRSD 5.3424 26.6748 0.200 0.8415
## promoSUN2 14.8586 13.9555 1.065 0.2886
## promoSY1 3.5060 22.7715 0.154 0.8778
## promoSY100 4.6518 22.9196 0.203 0.8394
## promoSY1000 1.9338 26.4809 0.073 0.9419
## promoSY2 1.0971 24.0691 0.046 0.9637
## promoSY200 8.3586 13.9555 0.599 0.5501
## promoSY250 13.1530 23.3349 0.564 0.5738
## promoSY5 20.2733 26.6890 0.760 0.4486
## promoSYVE 3.4191 26.5683 0.129 0.8978
## promoUP1 1.4645 10.7949 0.136 0.8923
## promoUP3 -2.8850 11.1504 -0.259 0.7962
## promoVIP 6.2674 25.7634 0.243 0.8081
## promoVPNB 10.2674 14.2014 0.723 0.4708
## promoWC1 17.2166 12.6616 1.360 0.1758
## promoWC2 19.2674 17.1492 1.124 0.2629
## promoWild Card -12.2574 24.4467 -0.501 0.6168
## month2 9.6175 5.0470 1.906 0.0585 .
## month3 3.3740 4.8627 0.694 0.4888
## month4 0.1365 4.8383 0.028 0.9775
## month5 -1.4046 5.8537 -0.240 0.8107
## month6 NA NA NA NA
## month7 3.2291 5.8128 0.556 0.5793
## month8 -2.6766 4.7424 -0.564 0.5733
## month9 NA NA NA NA
## month10 -7.5369 5.9201 -1.273 0.2049
## month11 -7.2725 5.4414 -1.337 0.1833
## month12 NA NA NA NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 13.6 on 158 degrees of freedom
## Multiple R-squared: 0.2243, Adjusted R-squared: 0.02301
## F-statistic: 1.114 on 41 and 158 DF, p-value: 0.3126
anova(lm3)
result$var[3] <- "lm(formula = Order_Qty ~ Qt + promo + month, data = lm_cust_s1)"
result$pval[3] <- "Adjusted R-squared: 0.2799 F-statistic: 3.09 on 37 and 162 DF, p-value: 4.911e-07"
result$comment[3] <- "(Month) least significant"
#4 Dropping Month
lm4 <- lm(Order_Qty ~ Qt + promo ,lm_cust_s1)
summary(lm4)
##
## Call:
## lm(formula = Order_Qty ~ Qt + promo, data = lm_cust_s1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -28.200 -6.871 -2.023 3.111 78.800
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 6.51577 9.87084 0.660 0.5101
## QtQ1_18 10.81104 19.63228 0.551 0.5826
## QtQ2_17 -2.03155 4.70074 -0.432 0.6662
## QtQ2_18 3.00000 19.17386 0.156 0.8759
## QtQ3_17 3.12864 19.69623 0.159 0.8740
## QtQ3_18 5.16104 19.62113 0.263 0.7928
## QtQ4_17 -1.40241 19.63734 -0.071 0.9432
## QtQ4_18 5.42945 19.69608 0.276 0.7832
## promoH15 7.63683 10.86250 0.703 0.4830
## promoLUX40 14.58087 10.52887 1.385 0.1680
## promoNASC75 26.51577 16.77056 1.581 0.1158
## promoNB 1.48423 13.76018 0.108 0.9142
## promoOOX40 17.82808 12.40144 1.438 0.1524
## promoOther 1.32318 21.76394 0.061 0.9516
## promoOY12 5.48423 16.77056 0.327 0.7441
## promoPB1 7.48423 16.77056 0.446 0.6560
## promoRB15 29.51577 16.77056 1.760 0.0803 .
## promoRSD 11.88664 25.82396 0.460 0.6459
## promoSUN2 17.01577 13.76018 1.237 0.2180
## promoSY1 3.94435 22.05667 0.179 0.8583
## promoSY100 7.40239 22.21911 0.333 0.7394
## promoSY1000 7.67318 25.82011 0.297 0.7667
## promoSY2 0.05478 23.38037 0.002 0.9981
## promoSY200 10.51577 13.76018 0.764 0.4458
## promoSY250 11.87318 22.79525 0.521 0.6032
## promoSY5 19.05478 25.86866 0.737 0.4624
## promoSYVE 2.32318 25.81164 0.090 0.9284
## promoUP1 3.04115 10.44178 0.291 0.7712
## promoUP3 -0.07819 10.91712 -0.007 0.9943
## promoVIP 7.48423 25.47329 0.294 0.7693
## promoVPNB 11.48423 13.76018 0.835 0.4051
## promoWC1 20.82808 12.40144 1.679 0.0949 .
## promoWC2 20.48423 16.77056 1.221 0.2237
## promoWild Card -11.32682 23.97434 -0.472 0.6372
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 13.56 on 166 degrees of freedom
## Multiple R-squared: 0.1895, Adjusted R-squared: 0.02835
## F-statistic: 1.176 on 33 and 166 DF, p-value: 0.2514
anova(lm4)
result$var[4] <- "lm(formula = Order_Qty ~ Qt + promo, data = lm_cust_s1)"
result$pval[4] <- "Adjusted R-squared: -0.003147 F-statistic: 0.9799 on 31 and 168 DF, p-value: 0.5038"
result$comment[4] <- "not much significant"
# 5 Increase Sample Size
rm(lm_cust_s1)
# SInce I see no major significance increasing the sample size to 500
set.seed(12121)
lm_cust_s2 <- lm_cust[sample(nrow(lm_cust),500),]
lm_cust_s2$month <- month(lm_cust_s2$`Order Date`)
lm_cust_s2$month <- as.factor(lm_cust_s2$month )
names(lm_cust_s2)
## [1] "KUNNR_NEW" "Qt" "Brand" "Order Date" "promo"
## [6] "city" "state" "Order_Qty" "Doll_Val" "month"
lm5 <- lm(Order_Qty ~ Qt + Brand + promo + month + state,lm_cust_s2)
summary(lm5)
##
## Call:
## lm(formula = Order_Qty ~ Qt + Brand + promo + month + state,
## data = lm_cust_s2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -33.494 -7.572 -1.467 4.583 259.806
##
## Coefficients: (3 not defined because of singularities)
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 20.14325 34.73837 0.580 0.5624
## QtQ1_18 -12.38201 13.68592 -0.905 0.3662
## QtQ2_17 -9.46505 6.69384 -1.414 0.1582
## QtQ2_18 -15.15304 14.22715 -1.065 0.2875
## QtQ3_17 -9.96147 14.17595 -0.703 0.4827
## QtQ3_18 -16.39689 14.49849 -1.131 0.2588
## QtQ4_17 -20.60796 14.37100 -1.434 0.1524
## QtQ4_18 -12.07142 14.66120 -0.823 0.4108
## BrandAX -5.93184 15.11709 -0.392 0.6950
## BrandBB 1.19151 20.69687 0.058 0.9541
## BrandBE -4.78670 14.38799 -0.333 0.7396
## BrandBV -22.57412 19.70034 -1.146 0.2526
## BrandCH -12.04660 16.94306 -0.711 0.4775
## BrandDG -9.85702 14.56936 -0.677 0.4991
## BrandDY 1.75232 21.38808 0.082 0.9347
## BrandEA 3.69546 16.12952 0.229 0.8189
## BrandHC -1.85858 13.65709 -0.136 0.8918
## BrandMK -3.69741 13.90020 -0.266 0.7904
## BrandMU -10.78838 16.52074 -0.653 0.5142
## BrandOJ -12.23249 21.30963 -0.574 0.5663
## BrandOO 4.61509 13.57490 0.340 0.7341
## BrandOX 4.43375 14.25313 0.311 0.7559
## BrandOY -6.96381 14.11707 -0.493 0.6221
## BrandPH -11.47871 13.98163 -0.821 0.4122
## BrandPO -5.07548 19.04164 -0.267 0.7900
## BrandPP -5.82629 17.21851 -0.338 0.7353
## BrandPR -8.90657 13.50053 -0.660 0.5098
## BrandPS -19.72345 14.99779 -1.315 0.1893
## BrandRA -12.24210 20.92701 -0.585 0.5589
## BrandRB 1.50802 13.22393 0.114 0.9093
## BrandRJ -14.42184 15.64738 -0.922 0.3573
## BrandRL -12.58423 15.60577 -0.806 0.4205
## BrandRX -2.99169 13.16636 -0.227 0.8204
## BrandRY -14.52809 13.27817 -1.094 0.2746
## BrandSF -10.81681 20.58147 -0.526 0.5995
## BrandTF -7.81851 14.24592 -0.549 0.5835
## BrandTY -14.82686 14.49356 -1.023 0.3070
## BrandVA 5.07855 21.07170 0.241 0.8097
## BrandVE -5.08421 13.92758 -0.365 0.7153
## BrandVO -6.53843 14.38871 -0.454 0.6498
## promoCODE F -15.70126 26.42017 -0.594 0.5527
## promoH15 -9.24165 24.63055 -0.375 0.7077
## promoHC18 -22.87087 37.20216 -0.615 0.5391
## promoLUX40 -1.03471 24.41081 -0.042 0.9662
## promoNASC150 -2.99490 29.18787 -0.103 0.9183
## promoNASC75 -14.83641 33.56867 -0.442 0.6588
## promoNB -10.14308 32.38604 -0.313 0.7543
## promoNB40 13.31739 32.60768 0.408 0.6832
## promoOO15 -4.58799 33.64289 -0.136 0.8916
## promoOOX40 9.98885 29.23441 0.342 0.7328
## promoOther 6.56118 27.49548 0.239 0.8115
## promoOY12 -1.15356 33.46079 -0.034 0.9725
## promoPB3 -3.53753 35.79019 -0.099 0.9213
## promoPRE-SELL T 1.26157 32.82228 0.038 0.9694
## promoPRE-SELL V 0.04740 42.43947 0.001 0.9991
## promoPRE SELL T -5.04635 33.45525 -0.151 0.8802
## promoRB15 10.77761 28.81100 0.374 0.7086
## promoRSD 22.70700 35.12479 0.646 0.5184
## promoSUN1 37.19751 32.74358 1.136 0.2567
## promoSY1 4.78064 28.00221 0.171 0.8645
## promoSY100 6.00226 27.68624 0.217 0.8285
## promoSY1000 4.81309 30.54350 0.158 0.8749
## promoSY2 -1.52005 29.37528 -0.052 0.9588
## promoSY200 7.58263 26.44625 0.287 0.7745
## promoSY250 18.56546 28.33298 0.655 0.5127
## promoSY5 8.20619 29.56529 0.278 0.7815
## promoSYNERGY54 -7.00092 28.33806 -0.247 0.8050
## promoSYVE 16.72686 28.90926 0.579 0.5632
## promoUP1 -5.89556 24.63619 -0.239 0.8110
## promoUP3 -13.58070 25.19473 -0.539 0.5902
## promoVIP 22.49923 29.20433 0.770 0.4416
## promoVP1200 -25.50758 33.25155 -0.767 0.4435
## promoVPFP200 7.64224 25.18866 0.303 0.7618
## promoWC1 23.41038 26.52423 0.883 0.3780
## promoWild Card 5.08864 31.07607 0.164 0.8700
## month2 -7.86552 5.24763 -1.499 0.1348
## month3 -2.84667 5.45975 -0.521 0.6024
## month4 9.59351 5.09722 1.882 0.0606 .
## month5 7.98950 4.92468 1.622 0.1056
## month6 NA NA NA NA
## month7 -4.03791 5.86721 -0.688 0.4918
## month8 -1.83638 4.44705 -0.413 0.6799
## month9 NA NA NA NA
## month10 0.19136 5.47634 0.035 0.9721
## month11 10.02477 5.34592 1.875 0.0616 .
## month12 NA NA NA NA
## stateAL -3.86751 25.77620 -0.150 0.8808
## stateAR 9.43907 26.93737 0.350 0.7262
## stateAZ 7.19716 22.51918 0.320 0.7495
## stateCA 10.92148 21.24314 0.514 0.6075
## stateCO -1.37323 21.92096 -0.063 0.9501
## stateCT 1.56498 22.18577 0.071 0.9438
## stateFL 9.96737 21.37418 0.466 0.6413
## stateGA 7.76887 21.73436 0.357 0.7210
## stateGU 55.34930 31.97985 1.731 0.0843 .
## stateHI -6.02231 24.57447 -0.245 0.8065
## stateIA 10.34710 24.51255 0.422 0.6732
## stateID 4.01486 30.18054 0.133 0.8942
## stateIL 3.39434 21.66533 0.157 0.8756
## stateIN 0.78569 22.91155 0.034 0.9727
## stateKS 0.27921 22.68561 0.012 0.9902
## stateKY 7.01166 22.27732 0.315 0.7531
## stateLA 6.61282 25.32635 0.261 0.7942
## stateMA -3.01567 22.79640 -0.132 0.8948
## stateMD 8.08368 23.50580 0.344 0.7311
## stateME -0.29373 24.35634 -0.012 0.9904
## stateMI -1.27804 22.09473 -0.058 0.9539
## stateMN -2.29799 23.70904 -0.097 0.9228
## stateMO 12.37066 22.96224 0.539 0.5904
## stateMS 2.34391 22.72796 0.103 0.9179
## stateMT 8.35430 26.06567 0.321 0.7488
## stateNC 1.91098 21.90083 0.087 0.9305
## stateND 7.31947 30.77008 0.238 0.8121
## stateNE -7.25877 23.64020 -0.307 0.7590
## stateNH 2.87995 24.84885 0.116 0.9078
## stateNJ 9.80019 21.78772 0.450 0.6531
## stateNM -0.22389 30.65327 -0.007 0.9942
## stateNV 8.35141 22.64371 0.369 0.7125
## stateNY 6.17187 21.39072 0.289 0.7731
## stateOH -0.02588 22.72123 -0.001 0.9991
## stateOK 12.51012 22.62553 0.553 0.5807
## stateOR 5.99219 22.97606 0.261 0.7944
## statePA -2.95395 21.82543 -0.135 0.8924
## statePR 17.22291 22.70442 0.759 0.4486
## stateRI -0.15320 29.89626 -0.005 0.9959
## stateSC -3.59822 24.04595 -0.150 0.8811
## stateTN 6.37490 22.92252 0.278 0.7811
## stateTX 7.12500 21.34097 0.334 0.7387
## stateUT -7.04796 23.59811 -0.299 0.7654
## stateVA -2.06891 24.60180 -0.084 0.9330
## stateVT -3.34033 29.73617 -0.112 0.9106
## stateWA -3.16528 23.24011 -0.136 0.8917
## stateWI -9.33238 29.88901 -0.312 0.7550
## stateWV 2.59632 31.03589 0.084 0.9334
## stateWY -7.91241 34.21432 -0.231 0.8172
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 20.4 on 368 degrees of freedom
## Multiple R-squared: 0.2427, Adjusted R-squared: -0.02682
## F-statistic: 0.9005 on 131 and 368 DF, p-value: 0.7576
anova(lm5)
result$var[5] <- "500: lm(formula = Order_Qty ~ Qt + Brand + promo + month + state, data = lm_cust_s2)"
result$pval[5] <- " Adjusted R-squared: 0.05218 F-statistic: 1.214 on 128 and 370 DF, p-value: 0.08366"
result$comment[5] <- "(Sig: Promo) "
#6 Dropping Month, I want to keep state for now.
lm6 <- lm(Order_Qty ~ Qt + Brand + promo + state,lm_cust_s2)
summary(lm6)
##
## Call:
## lm(formula = Order_Qty ~ Qt + Brand + promo + state, data = lm_cust_s2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -28.127 -7.511 -1.505 4.252 268.474
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 8.02960 34.30241 0.234 0.8150
## QtQ1_18 -6.62931 13.58937 -0.488 0.6260
## QtQ2_17 -0.07944 5.10610 -0.016 0.9876
## QtQ2_18 -1.41508 13.27754 -0.107 0.9152
## QtQ3_17 -2.28899 13.36886 -0.171 0.8641
## QtQ3_18 -8.30409 13.56042 -0.612 0.5407
## QtQ4_17 -6.47382 12.98965 -0.498 0.6185
## QtQ4_18 -0.68162 13.61072 -0.050 0.9601
## BrandAX -5.24418 15.00420 -0.350 0.7269
## BrandBB -1.86942 20.63607 -0.091 0.9279
## BrandBE -4.64213 14.36805 -0.323 0.7468
## BrandBV -18.47433 19.58435 -0.943 0.3461
## BrandCH -9.37833 16.86124 -0.556 0.5784
## BrandDG -9.46028 14.48665 -0.653 0.5141
## BrandDY -4.62203 21.26211 -0.217 0.8280
## BrandEA 4.55126 16.10243 0.283 0.7776
## BrandHC -0.51819 13.61044 -0.038 0.9696
## BrandMK -3.10084 13.86387 -0.224 0.8231
## BrandMU -11.10187 16.49254 -0.673 0.5013
## BrandOJ -13.02060 21.17600 -0.615 0.5390
## BrandOO 4.85366 13.50752 0.359 0.7196
## BrandOX 4.57275 14.23692 0.321 0.7482
## BrandOY -6.54991 14.12100 -0.464 0.6430
## BrandPH -11.38116 13.96818 -0.815 0.4157
## BrandPO -3.99850 19.02848 -0.210 0.8337
## BrandPP -7.46227 17.03407 -0.438 0.6616
## BrandPR -6.58560 13.46938 -0.489 0.6252
## BrandPS -18.00037 14.97084 -1.202 0.2300
## BrandRA -13.00028 20.75422 -0.626 0.5314
## BrandRB 2.15040 13.20372 0.163 0.8707
## BrandRJ -15.82872 15.61486 -1.014 0.3114
## BrandRL -12.50697 15.55294 -0.804 0.4218
## BrandRX -2.03237 13.13140 -0.155 0.8771
## BrandRY -13.47718 13.23821 -1.018 0.3093
## BrandSF -9.44177 20.51900 -0.460 0.6457
## BrandTF -7.34934 14.19749 -0.518 0.6050
## BrandTY -15.01981 14.45416 -1.039 0.2994
## BrandVA 1.38709 21.05845 0.066 0.9475
## BrandVE -4.53773 13.92096 -0.326 0.7446
## BrandVO -6.22499 14.34452 -0.434 0.6646
## promoCODE F -9.25451 26.32037 -0.352 0.7253
## promoH15 -1.90017 24.55474 -0.077 0.9384
## promoHC18 -7.70355 36.66452 -0.210 0.8337
## promoLUX40 4.70290 24.32608 0.193 0.8468
## promoNASC150 6.83773 29.10439 0.235 0.8144
## promoNASC75 -5.37040 33.57992 -0.160 0.8730
## promoNB -1.95693 32.14311 -0.061 0.9515
## promoNB40 20.15586 32.26949 0.625 0.5326
## promoOO15 -3.29398 33.60503 -0.098 0.9220
## promoOOX40 14.60444 29.06348 0.503 0.6156
## promoOther 6.84500 27.41425 0.250 0.8030
## promoOY12 10.59259 32.99069 0.321 0.7483
## promoPB3 7.05241 35.46387 0.199 0.8425
## promoPRE-SELL T 2.58398 32.94963 0.078 0.9375
## promoPRE-SELL V 12.36557 42.42057 0.291 0.7708
## promoPRE SELL T 4.86633 33.15357 0.147 0.8834
## promoRB15 14.61887 28.64691 0.510 0.6101
## promoRSD 25.33896 34.85237 0.727 0.4677
## promoSUN1 44.96085 32.49578 1.384 0.1673
## promoSY1 7.74770 27.91065 0.278 0.7815
## promoSY100 6.84815 27.61190 0.248 0.8043
## promoSY1000 3.94037 30.33851 0.130 0.8967
## promoSY2 2.65038 29.32512 0.090 0.9280
## promoSY200 10.11257 26.29383 0.385 0.7008
## promoSY250 19.06825 28.19119 0.676 0.4992
## promoSY5 8.35961 29.37713 0.285 0.7761
## promoSYNERGY54 -3.04753 28.26101 -0.108 0.9142
## promoSYVE 17.74689 28.81123 0.616 0.5383
## promoUP1 1.26964 24.50377 0.052 0.9587
## promoUP3 -6.14618 25.04891 -0.245 0.8063
## promoVIP 19.85365 29.03511 0.684 0.4945
## promoVP1200 -13.55903 32.85159 -0.413 0.6800
## promoVPFP200 14.44690 24.75839 0.584 0.5599
## promoWC1 26.75784 26.42159 1.013 0.3118
## promoWild Card 6.11712 30.89824 0.198 0.8432
## stateAL -0.97446 25.62438 -0.038 0.9697
## stateAR 9.38985 26.83588 0.350 0.7266
## stateAZ 7.53285 22.48932 0.335 0.7378
## stateCA 12.47958 21.23239 0.588 0.5570
## stateCO 0.93859 21.89031 0.043 0.9658
## stateCT 3.17577 22.17152 0.143 0.8862
## stateFL 11.85637 21.37329 0.555 0.5794
## stateGA 9.34873 21.70326 0.431 0.6669
## stateGU 60.18126 31.99879 1.881 0.0608 .
## stateHI -7.00034 24.51760 -0.286 0.7754
## stateIA 12.43935 24.51708 0.507 0.6122
## stateID 1.96774 30.18050 0.065 0.9481
## stateIL 4.41483 21.67815 0.204 0.8387
## stateIN 2.25104 22.87744 0.098 0.9217
## stateKS 2.73577 22.58748 0.121 0.9037
## stateKY 5.62282 22.29858 0.252 0.8011
## stateLA 8.61040 25.25996 0.341 0.7334
## stateMA 1.73441 22.62796 0.077 0.9389
## stateMD 9.14952 23.58489 0.388 0.6983
## stateME 0.78155 24.41827 0.032 0.9745
## stateMI 0.48669 22.06065 0.022 0.9824
## stateMN 1.53324 23.62358 0.065 0.9483
## stateMO 12.16391 22.89886 0.531 0.5956
## stateMS 5.04088 22.68813 0.222 0.8243
## stateMT 11.10565 25.93029 0.428 0.6687
## stateNC 3.99643 21.87168 0.183 0.8551
## stateND 4.05635 30.63815 0.132 0.8947
## stateNE -3.08792 23.68299 -0.130 0.8963
## stateNH 7.46211 24.87698 0.300 0.7644
## stateNJ 11.35090 21.76356 0.522 0.6023
## stateNM 0.96618 30.62577 0.032 0.9748
## stateNV 11.06237 22.58335 0.490 0.6245
## stateNY 8.56472 21.36350 0.401 0.6887
## stateOH -0.07229 22.74599 -0.003 0.9975
## stateOK 12.64305 22.61100 0.559 0.5764
## stateOR 6.50885 22.86981 0.285 0.7761
## statePA -1.51525 21.81498 -0.069 0.9447
## statePR 16.04762 22.61323 0.710 0.4784
## stateRI 6.57286 29.69666 0.221 0.8250
## stateSC -2.80658 23.99163 -0.117 0.9069
## stateTN 9.94518 22.81704 0.436 0.6632
## stateTX 8.18250 21.32964 0.384 0.7015
## stateUT -3.72114 23.49325 -0.158 0.8742
## stateVA 1.15410 24.56771 0.047 0.9626
## stateVT -1.15835 29.88522 -0.039 0.9691
## stateWA -3.19136 23.26941 -0.137 0.8910
## stateWI -9.34337 29.78732 -0.314 0.7539
## stateWV -1.78225 31.07091 -0.057 0.9543
## stateWY 0.56109 33.93408 0.017 0.9868
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 20.51 on 376 degrees of freedom
## Multiple R-squared: 0.2178, Adjusted R-squared: -0.03802
## F-statistic: 0.8514 on 123 and 376 DF, p-value: 0.854
anova(lm6)
result$var[6] <- "lm(formula = Order_Qty ~ Qt + Brand + promo + state, data = lm_cust_s2)"
result$pval[6] <- "Adjusted R-squared: 0.04593 F-statistic: 1.2 on 120 and 378 DF, p-value: 0.1016"
result$comment[6] <- "promo is very less significant now, nothing else is significant"
#7 Drop Brand
set.seed(12123)
lm7 <- lm(Order_Qty ~ Qt + promo + state,lm_cust_s2)
summary(lm7)
##
## Call:
## lm(formula = Order_Qty ~ Qt + promo + state, data = lm_cust_s2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -29.064 -8.453 -1.871 3.679 275.634
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -5.8361 29.6841 -0.197 0.8442
## QtQ1_18 -6.8155 13.1503 -0.518 0.6045
## QtQ2_17 2.9903 4.8709 0.614 0.5396
## QtQ2_18 -3.2517 12.8969 -0.252 0.8011
## QtQ3_17 -2.4078 13.0583 -0.184 0.8538
## QtQ3_18 -9.4536 13.1759 -0.717 0.4735
## QtQ4_17 -6.6945 12.6442 -0.529 0.5968
## QtQ4_18 -0.3352 13.2263 -0.025 0.9798
## promoCODE F -2.4828 23.7023 -0.105 0.9166
## promoH15 4.5176 21.9520 0.206 0.8371
## promoHC18 2.2103 30.6962 0.072 0.9426
## promoLUX40 8.9112 21.7017 0.411 0.6816
## promoNASC150 8.8157 26.2911 0.335 0.7376
## promoNASC75 -1.7234 31.0307 -0.056 0.9557
## promoNB 9.3594 30.2236 0.310 0.7570
## promoNB40 20.5520 30.0894 0.683 0.4950
## promoOO15 3.2297 31.8710 0.101 0.9193
## promoOOX40 27.2252 26.2994 1.035 0.3012
## promoOther 14.2439 24.9554 0.571 0.5685
## promoOY12 14.4652 30.5713 0.473 0.6364
## promoPB3 1.4279 30.0617 0.047 0.9621
## promoPRE-SELL T 2.7075 30.4716 0.089 0.9292
## promoPRE-SELL V 24.2461 36.9827 0.656 0.5124
## promoPRE SELL T 5.3817 30.8016 0.175 0.8614
## promoRB15 25.7572 26.3920 0.976 0.3297
## promoRSD 38.3215 32.5861 1.176 0.2403
## promoSUN1 51.4376 30.5036 1.686 0.0925 .
## promoSY1 13.5194 25.3683 0.533 0.5944
## promoSY100 11.0945 25.1804 0.441 0.6597
## promoSY1000 6.8399 27.8822 0.245 0.8063
## promoSY2 8.9155 26.9312 0.331 0.7408
## promoSY200 12.7831 23.6287 0.541 0.5888
## promoSY250 24.1831 25.7689 0.938 0.3486
## promoSY5 13.3775 27.0189 0.495 0.6208
## promoSYNERGY54 6.5813 26.5173 0.248 0.8041
## promoSYVE 25.3445 26.3357 0.962 0.3364
## promoUP1 5.3629 21.8511 0.245 0.8062
## promoUP3 1.6612 22.3605 0.074 0.9408
## promoVIP 28.6234 26.4531 1.082 0.2799
## promoVP1200 -0.9022 30.7409 -0.029 0.9766
## promoVPFP200 19.8060 23.2491 0.852 0.3948
## promoWC1 31.3040 23.9135 1.309 0.1913
## promoWild Card 9.0270 27.9390 0.323 0.7468
## stateAL 5.7039 25.3243 0.225 0.8219
## stateAR 16.3473 25.4957 0.641 0.5218
## stateAZ 10.4641 22.1373 0.473 0.6367
## stateCA 16.2938 20.9567 0.778 0.4373
## stateCO 7.4082 21.5097 0.344 0.7307
## stateCT 7.3483 21.7572 0.338 0.7357
## stateFL 13.4864 21.1499 0.638 0.5241
## stateGA 13.8361 21.3742 0.647 0.5178
## stateGU 73.7475 31.5818 2.335 0.0200 *
## stateHI 2.1359 23.9752 0.089 0.9291
## stateIA 22.7525 24.2334 0.939 0.3483
## stateID 14.8440 29.4220 0.505 0.6142
## stateIL 8.2861 21.3532 0.388 0.6982
## stateIN 6.9454 22.3788 0.310 0.7564
## stateKS 9.1286 22.1756 0.412 0.6808
## stateKY 4.6355 22.0256 0.210 0.8334
## stateLA 4.7482 24.1050 0.197 0.8439
## stateMA 6.3419 22.3157 0.284 0.7764
## stateMD 13.5545 23.2315 0.583 0.5599
## stateME 2.9414 24.1003 0.122 0.9029
## stateMI 4.9335 21.5874 0.229 0.8193
## stateMN 5.2760 23.2849 0.227 0.8209
## stateMO 12.0141 22.5223 0.533 0.5940
## stateMS 7.0995 22.3247 0.318 0.7506
## stateMT 8.2268 25.5198 0.322 0.7473
## stateNC 5.4109 21.5368 0.251 0.8018
## stateND 4.4362 29.8414 0.149 0.8819
## stateNE 5.3056 23.3057 0.228 0.8200
## stateNH 14.8982 23.9116 0.623 0.5336
## stateNJ 14.4608 21.5010 0.673 0.5016
## stateNM 9.1749 30.3381 0.302 0.7625
## stateNV 13.5692 22.3122 0.608 0.5434
## stateNY 10.7664 21.0482 0.512 0.6093
## stateOH 3.3710 22.2115 0.152 0.8794
## stateOK 14.5818 22.1722 0.658 0.5111
## stateOR 7.0323 22.5228 0.312 0.7550
## statePA 2.7267 21.5007 0.127 0.8991
## statePR 16.7383 22.4576 0.745 0.4565
## stateRI 12.8440 29.4220 0.437 0.6627
## stateSC 3.6161 23.3850 0.155 0.8772
## stateTN 12.8652 22.4051 0.574 0.5661
## stateTX 10.8475 21.1097 0.514 0.6076
## stateUT 1.8271 23.3345 0.078 0.9376
## stateVA 1.9079 24.2370 0.079 0.9373
## stateVT 10.0000 29.1305 0.343 0.7316
## stateWA -1.7696 22.8754 -0.077 0.9384
## stateWI -1.0726 29.4932 -0.036 0.9710
## stateWV 1.5901 30.4667 0.052 0.9584
## stateWY -4.1560 29.4220 -0.141 0.8877
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 20.6 on 408 degrees of freedom
## Multiple R-squared: 0.1441, Adjusted R-squared: -0.04684
## F-statistic: 0.7547 on 91 and 408 DF, p-value: 0.9483
anova(lm7)
result$var[7] <- "lm(formula = Order_Qty ~ Qt + promo + state, data = lm_cust_s2)"
result$pval[7] <- "Adjusted R-squared: 0.04285 F-statistic: 1.251 on 89 and 409 DF, p-value: 0.07818"
result$comment[7] <- "not much. sig "
#8 Drop state and Brand
set.seed(12126)
lm8 <- lm(Order_Qty ~ Qt + promo + Brand,lm_cust_s2)
summary(lm8)
##
## Call:
## lm(formula = Order_Qty ~ Qt + promo + Brand, data = lm_cust_s2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -25.499 -8.105 -1.961 3.530 275.230
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 15.63730 25.68654 0.609 0.543
## QtQ1_18 -0.58682 12.29368 -0.048 0.962
## QtQ2_17 -2.17451 4.70740 -0.462 0.644
## QtQ2_18 4.60028 12.02397 0.383 0.702
## QtQ3_17 3.34840 12.09371 0.277 0.782
## QtQ3_18 -1.50272 12.23675 -0.123 0.902
## QtQ4_17 -0.16126 11.65991 -0.014 0.989
## QtQ4_18 4.47973 12.31442 0.364 0.716
## promoCODE F -5.95422 25.20613 -0.236 0.813
## promoH15 0.04934 23.35115 0.002 0.998
## promoHC18 -0.77270 34.16125 -0.023 0.982
## promoLUX40 8.38598 23.08882 0.363 0.717
## promoNASC150 12.91374 27.69123 0.466 0.641
## promoNASC75 1.12986 31.22372 0.036 0.971
## promoNB 6.12749 30.66514 0.200 0.842
## promoNB40 26.49368 30.80911 0.860 0.390
## promoOO15 -9.87251 30.66514 -0.322 0.748
## promoOOX40 14.03684 27.26014 0.515 0.607
## promoOther 1.02133 25.57811 0.040 0.968
## promoOY12 2.72967 30.61166 0.089 0.929
## promoPB3 5.26925 32.43063 0.162 0.871
## promoPRE-SELL T -2.01869 30.81789 -0.066 0.948
## promoPRE-SELL V 12.24363 33.41101 0.366 0.714
## promoPRE SELL T 7.15582 31.18429 0.229 0.819
## promoRB15 17.12749 27.19421 0.630 0.529
## promoRSD 21.33846 32.76436 0.651 0.515
## promoSUN1 42.12749 30.66514 1.374 0.170
## promoSY1 4.12327 26.04488 0.158 0.874
## promoSY100 4.05058 25.72637 0.157 0.875
## promoSY1000 2.09977 28.37520 0.074 0.941
## promoSY2 -0.73703 27.33003 -0.027 0.978
## promoSY200 18.16933 24.83652 0.732 0.465
## promoSY250 15.09253 26.24829 0.575 0.566
## promoSY5 5.61552 27.31580 0.206 0.837
## promoSYNERGY54 -7.42698 26.25011 -0.283 0.777
## promoSYVE 11.95307 26.92468 0.444 0.657
## promoUP1 3.68509 23.19796 0.159 0.874
## promoUP3 -3.39548 23.77836 -0.143 0.887
## promoVIP 15.77279 27.44812 0.575 0.566
## promoVP1200 -4.06126 30.46462 -0.133 0.894
## promoVPFP200 16.80703 23.52874 0.714 0.475
## promoWC1 23.86248 24.97679 0.955 0.340
## promoWild Card 3.32694 28.99871 0.115 0.909
## BrandAX -10.04663 14.16467 -0.709 0.479
## BrandBB -8.69009 19.17740 -0.453 0.651
## BrandBE -5.59265 13.47393 -0.415 0.678
## BrandBV -15.26682 18.75551 -0.814 0.416
## BrandCH -7.63730 16.06693 -0.475 0.635
## BrandDG -12.67108 13.58884 -0.932 0.352
## BrandDY -8.29197 18.96041 -0.437 0.662
## BrandEA 4.40891 15.25730 0.289 0.773
## BrandHC -1.57604 12.74416 -0.124 0.902
## BrandMK -5.15996 13.09671 -0.394 0.694
## BrandMU -12.17703 15.75989 -0.773 0.440
## BrandOJ -17.90655 16.95110 -1.056 0.291
## BrandOO 3.63116 12.71348 0.286 0.775
## BrandOX 1.91312 13.11540 0.146 0.884
## BrandOY -6.36696 13.10011 -0.486 0.627
## BrandPH -11.91577 12.95562 -0.920 0.358
## BrandPO -1.33503 17.23805 -0.077 0.938
## BrandPP -11.41569 15.91653 -0.717 0.474
## BrandPR -5.95648 12.61475 -0.472 0.637
## BrandPS -16.53955 14.20647 -1.164 0.245
## BrandRA -15.20685 19.87971 -0.765 0.445
## BrandRB 0.40972 12.38283 0.033 0.974
## BrandRJ -15.27484 14.75218 -1.035 0.301
## BrandRL -16.03844 14.68319 -1.092 0.275
## BrandRX -3.91831 12.37546 -0.317 0.752
## BrandRY -14.33431 12.45980 -1.150 0.251
## BrandSF -16.16536 18.74040 -0.863 0.389
## BrandTF -7.61861 13.35475 -0.570 0.569
## BrandTY -14.60137 13.73456 -1.063 0.288
## BrandVA -7.88093 19.11869 -0.412 0.680
## BrandVE -7.49532 13.10598 -0.572 0.568
## BrandVO -7.62982 13.48761 -0.566 0.572
##
## Residual standard error: 20.04 on 425 degrees of freedom
## Multiple R-squared: 0.156, Adjusted R-squared: 0.009023
## F-statistic: 1.061 on 74 and 425 DF, p-value: 0.3527
anova(lm8)
result$var[8] <- "lm(formula = Order_Qty ~ Qt + promo + Brand, data = lm_cust_s2)"
result$pval[8] <- "Adjusted R-squared: 0.04555 F-statistic: 1.34 on 70 and 429 DF, p-value: 0.04416"
result$comment[8] <- "not much sig."
lm9 <- lm(formula = Order_Qty ~ Qt + Brand + promo + month, data = lm_cust_s2)
summary(lm9)
##
## Call:
## lm(formula = Order_Qty ~ Qt + Brand + promo + month, data = lm_cust_s2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -29.848 -8.309 -1.492 3.727 267.585
##
## Coefficients: (3 not defined because of singularities)
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 25.4685 26.1218 0.975 0.3301
## QtQ1_18 -5.6092 12.4000 -0.452 0.6513
## QtQ2_17 -10.9398 6.2077 -1.762 0.0787 .
## QtQ2_18 -8.1666 12.9309 -0.632 0.5280
## QtQ3_17 -4.3543 12.8939 -0.338 0.7358
## QtQ3_18 -9.4580 13.1511 -0.719 0.4724
## QtQ4_17 -12.8841 13.0152 -0.990 0.3228
## QtQ4_18 -5.8497 13.3477 -0.438 0.6614
## BrandAX -9.4196 14.2668 -0.660 0.5095
## BrandBB -5.9477 19.2645 -0.309 0.7577
## BrandBE -5.6269 13.5310 -0.416 0.6777
## BrandBV -18.2668 18.8627 -0.968 0.3334
## BrandCH -9.7403 16.1615 -0.603 0.5470
## BrandDG -12.0797 13.6682 -0.884 0.3773
## BrandDY -3.4774 19.0779 -0.182 0.8555
## BrandEA 4.2133 15.2976 0.275 0.7831
## BrandHC -2.0489 12.7963 -0.160 0.8729
## BrandMK -5.1656 13.1435 -0.393 0.6945
## BrandMU -11.2197 15.7994 -0.710 0.4780
## BrandOJ -18.8207 16.9621 -1.110 0.2678
## BrandOO 3.8081 12.7939 0.298 0.7661
## BrandOX 2.5956 13.1523 0.197 0.8436
## BrandOY -5.7431 13.1197 -0.438 0.6618
## BrandPH -11.2629 12.9928 -0.867 0.3865
## BrandPO -1.1515 17.2574 -0.067 0.9468
## BrandPP -9.4005 16.1514 -0.582 0.5609
## BrandPR -7.2997 12.6564 -0.577 0.5644
## BrandPS -17.9144 14.2381 -1.258 0.2090
## BrandRA -13.4667 20.0193 -0.673 0.5015
## BrandRB 0.1095 12.4167 0.009 0.9930
## BrandRJ -13.2835 14.8080 -0.897 0.3702
## BrandRL -15.4852 14.7574 -1.049 0.2946
## BrandRX -4.2402 12.4251 -0.341 0.7331
## BrandRY -14.6180 12.5106 -1.168 0.2433
## BrandSF -16.2623 18.8171 -0.864 0.3880
## BrandTF -7.1494 13.3948 -0.534 0.5938
## BrandTY -13.2043 13.7958 -0.957 0.3391
## BrandVA -4.2358 19.1546 -0.221 0.8251
## BrandVE -7.7708 13.1376 -0.591 0.5545
## BrandVO -7.0594 13.5342 -0.522 0.6022
## promoCODE F -12.4659 25.3217 -0.492 0.6228
## promoH15 -6.8867 23.4434 -0.294 0.7691
## promoHC18 -10.8878 34.5514 -0.315 0.7528
## promoLUX40 2.8168 23.1718 0.122 0.9033
## promoNASC150 2.7370 27.8081 0.098 0.9216
## promoNASC75 -8.7704 31.3382 -0.280 0.7797
## promoNB -0.9450 30.9199 -0.031 0.9756
## promoNB40 20.4642 31.0706 0.659 0.5105
## promoOO15 -10.6382 30.7639 -0.346 0.7297
## promoOOX40 9.6565 27.4174 0.352 0.7249
## promoOther 0.1816 25.6711 0.007 0.9944
## promoOY12 -7.7255 30.9532 -0.250 0.8030
## promoPB3 -3.6479 32.7594 -0.111 0.9114
## promoPRE-SELL T -4.5909 30.7320 -0.149 0.8813
## promoPRE-SELL V 6.4955 33.3576 0.195 0.8457
## promoPRE SELL T -0.6861 31.4486 -0.022 0.9826
## promoRB15 13.2084 27.3305 0.483 0.6291
## promoRSD 18.4402 33.0220 0.558 0.5769
## promoSUN1 35.0550 30.9199 1.134 0.2576
## promoSY1 1.2098 26.1433 0.046 0.9631
## promoSY100 2.8471 25.8205 0.110 0.9123
## promoSY1000 2.7455 28.5773 0.096 0.9235
## promoSY2 -5.0276 27.4162 -0.183 0.8546
## promoSY200 14.2891 24.9980 0.572 0.5679
## promoSY250 13.9756 26.4013 0.529 0.5968
## promoSY5 4.5020 27.5171 0.164 0.8701
## promoSYNERGY54 -9.8122 26.3440 -0.372 0.7097
## promoSYVE 10.3155 27.0718 0.381 0.7034
## promoUP1 -3.0098 23.3087 -0.129 0.8973
## promoUP3 -9.6455 23.9144 -0.403 0.6869
## promoVIP 17.4621 27.6093 0.632 0.5274
## promoVP1200 -13.4196 30.7206 -0.437 0.6625
## promoVPFP200 10.8929 23.9499 0.455 0.6495
## promoWC1 20.8624 25.0744 0.832 0.4059
## promoWild Card 1.8410 29.1719 0.063 0.9497
## month2 -7.7282 4.8906 -1.580 0.1148
## month3 -3.5016 5.0938 -0.687 0.4922
## month4 8.8686 4.7010 1.887 0.0599 .
## month5 6.3068 4.5112 1.398 0.1628
## month6 NA NA NA NA
## month7 -2.0712 5.5160 -0.375 0.7075
## month8 -1.4940 4.0877 -0.365 0.7149
## month9 NA NA NA NA
## month10 -0.6478 5.0822 -0.127 0.8986
## month11 8.8062 4.9822 1.768 0.0779 .
## month12 NA NA NA NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 19.96 on 417 degrees of freedom
## Multiple R-squared: 0.1786, Adjusted R-squared: 0.01712
## F-statistic: 1.106 on 82 and 417 DF, p-value: 0.2631
anova(lm9)
result$var[9] <- "lm(formula = Order_Qty ~ Qt + Brand + promo + month, data = lm_cust_s2)"
result$pval[9] <- "Adjusted R-squared: 0.05115 F-statistic: 1.345 on 78 and 421 DF, p-value: 0.03633"
result$comment[9] <- "Pvalue looks less than to .05"
lm10 <- lm(formula = Order_Qty ~ Qt + promo + month, data = lm_cust_s2)
summary(lm10)
##
## Call:
## lm(formula = Order_Qty ~ Qt + promo + month, data = lm_cust_s2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -31.892 -8.505 -2.770 3.470 275.180
##
## Coefficients: (3 not defined because of singularities)
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 15.29416 20.61528 0.742 0.4585
## QtQ1_18 -5.52179 11.94717 -0.462 0.6442
## QtQ2_17 -9.29586 5.95698 -1.560 0.1193
## QtQ2_18 -10.62355 12.44912 -0.853 0.3939
## QtQ3_17 -5.27074 12.52031 -0.421 0.6740
## QtQ3_18 -12.13249 12.64870 -0.959 0.3380
## QtQ4_17 -12.52851 12.52000 -1.001 0.3175
## QtQ4_18 -5.19040 12.88812 -0.403 0.6873
## promoCODE F -5.21900 22.89544 -0.228 0.8198
## promoH15 -1.72497 20.99034 -0.082 0.9345
## promoHC18 -9.99558 29.01323 -0.345 0.7306
## promoLUX40 6.06913 20.69518 0.293 0.7695
## promoNASC150 4.38215 25.26473 0.173 0.8624
## promoNASC75 -6.11785 28.97415 -0.211 0.8329
## promoNB 6.00442 29.01323 0.207 0.8361
## promoNB40 20.00442 29.01323 0.689 0.4909
## promoOO15 -1.99830 28.95670 -0.069 0.9450
## promoOOX40 22.61872 24.95844 0.906 0.3653
## promoOther 5.93621 23.31379 0.255 0.7991
## promoOY12 -3.29416 28.76421 -0.115 0.9089
## promoPB3 -12.29416 28.76421 -0.427 0.6693
## promoPRE-SELL T -2.00000 28.36864 -0.071 0.9438
## promoPRE-SELL V 12.00000 28.36864 0.423 0.6725
## promoPRE SELL T -0.99558 29.01323 -0.034 0.9726
## promoRB15 21.00306 25.18059 0.834 0.4047
## promoRSD 27.33211 30.95101 0.883 0.3777
## promoSUN1 42.00442 29.01323 1.448 0.1484
## promoSY1 4.69157 23.68312 0.198 0.8431
## promoSY100 4.63037 23.50161 0.197 0.8439
## promoSY1000 5.01228 26.28522 0.191 0.8489
## promoSY2 -1.40579 25.13091 -0.056 0.9554
## promoSY200 17.05300 22.48596 0.758 0.4486
## promoSY250 18.07762 24.12589 0.749 0.4541
## promoSY5 6.74014 25.26120 0.267 0.7897
## promoSYNERGY54 -3.12684 24.55611 -0.127 0.8987
## promoSYVE 16.89315 24.74080 0.683 0.4951
## promoUP1 -0.09184 20.84021 -0.004 0.9965
## promoUP3 -3.15163 21.41517 -0.147 0.8831
## promoVIP 25.72993 25.09768 1.025 0.3058
## promoVP1200 -5.29416 28.76421 -0.184 0.8541
## promoVPFP200 17.03574 22.45344 0.759 0.4484
## promoWC1 24.34589 22.61936 1.076 0.2824
## promoWild Card 4.50231 26.20562 0.172 0.8637
## month2 -7.29416 4.75394 -1.534 0.1257
## month3 -5.52990 4.87257 -1.135 0.2570
## month4 9.11955 4.58482 1.989 0.0473 *
## month5 7.99728 4.41454 1.812 0.0707 .
## month6 NA NA NA NA
## month7 -0.14539 5.34835 -0.027 0.9783
## month8 0.61627 3.94551 0.156 0.8759
## month9 NA NA NA NA
## month10 -1.83139 4.93105 -0.371 0.7105
## month11 8.78052 4.79840 1.830 0.0679 .
## month12 NA NA NA NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 20.06 on 449 degrees of freedom
## Multiple R-squared: 0.1067, Adjusted R-squared: 0.007203
## F-statistic: 1.072 on 50 and 449 DF, p-value: 0.3482
anova(lm10)
result$var[10] <- "lm(formula = Order_Qty ~ Qt + promo + month, data = lm_cust_s2)"
result$pval[10] <- "Adjusted R-squared: 0.0448
F-statistic: 1.498 on 47 and 452 DF, p-value: 0.02147"
result$comment[10] <- "not much sig."
# p-value: 0.02331
lm_pbm <- lm(formula = Order_Qty ~ promo + Brand + month, data = lm_cust_s2)
summary(lm(formula = Order_Qty ~ promo + Brand + month, data = lm_cust_s2))
##
## Call:
## lm(formula = Order_Qty ~ promo + Brand + month, data = lm_cust_s2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -28.914 -8.133 -1.654 3.478 272.944
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 26.13481 26.10286 1.001 0.317
## promoCODE F -15.96890 25.23730 -0.633 0.527
## promoH15 -8.72719 23.45000 -0.372 0.710
## promoHC18 -19.24662 34.26227 -0.562 0.575
## promoLUX40 0.65737 23.17376 0.028 0.977
## promoNASC150 -1.28252 27.65930 -0.046 0.963
## promoNASC75 -14.85914 31.18716 -0.476 0.634
## promoNB -6.14625 30.76470 -0.200 0.842
## promoNB40 15.07273 30.93316 0.487 0.626
## promoOO15 -16.15442 30.59427 -0.528 0.598
## promoOOX40 6.81802 27.41124 0.249 0.804
## promoOther -3.73615 22.87707 -0.163 0.870
## promoOY12 -7.04911 31.00791 -0.227 0.820
## promoPB3 -6.01193 32.81257 -0.183 0.855
## promoPRE-SELL T -4.13293 30.79075 -0.134 0.893
## promoPRE-SELL V 7.67132 33.41142 0.230 0.819
## promoPRE SELL T -5.42158 31.26403 -0.173 0.862
## promoRB15 7.84967 27.13088 0.289 0.772
## promoRSD 16.07839 30.92792 0.520 0.603
## promoSUN1 29.85375 30.76470 0.970 0.332
## promoSY1 0.03163 23.35211 0.001 0.999
## promoSY100 -0.56330 23.22642 -0.024 0.981
## promoSY1000 -3.43163 25.67911 -0.134 0.894
## promoSY2 -4.81010 24.79152 -0.194 0.846
## promoSY200 8.62250 24.36471 0.354 0.724
## promoSY250 8.06814 23.49242 0.343 0.731
## promoSY5 3.93312 24.81882 0.158 0.874
## promoSYNERGY54 -9.85176 23.61471 -0.417 0.677
## promoSYVE 3.35126 24.29424 0.138 0.890
## promoUP1 -5.59888 23.29931 -0.240 0.810
## promoUP3 -13.01644 23.86255 -0.545 0.586
## promoVIP 14.93715 24.92897 0.599 0.549
## promoVP1200 -13.31577 30.77976 -0.433 0.666
## promoVPFP200 10.07814 23.99677 0.420 0.675
## promoWC1 17.74550 24.22135 0.733 0.464
## promoWild Card -4.61956 26.46511 -0.175 0.862
## BrandAX -10.95095 13.99807 -0.782 0.434
## BrandBB -3.49403 19.13093 -0.183 0.855
## BrandBE -4.82203 13.43485 -0.359 0.720
## BrandBV -19.33190 18.85157 -1.025 0.306
## BrandCH -10.45199 16.05497 -0.651 0.515
## BrandDG -13.11649 13.48968 -0.972 0.331
## BrandDY -6.86874 18.90344 -0.363 0.717
## BrandEA 4.50472 15.22928 0.296 0.768
## BrandHC -2.81904 12.67625 -0.222 0.824
## BrandMK -5.46062 13.01448 -0.420 0.675
## BrandMU -12.97826 15.65353 -0.829 0.408
## BrandOJ -17.12288 16.84112 -1.017 0.310
## BrandOO 2.50665 12.69621 0.197 0.844
## BrandOX 1.61952 13.06314 0.124 0.901
## BrandOY -7.08570 12.97111 -0.546 0.585
## BrandPH -11.87732 12.88164 -0.922 0.357
## BrandPO -3.96044 17.19708 -0.230 0.818
## BrandPP -13.70844 16.01366 -0.856 0.392
## BrandPR -7.81338 12.60822 -0.620 0.536
## BrandPS -17.09130 14.11834 -1.211 0.227
## BrandRA -12.97364 19.96227 -0.650 0.516
## BrandRB -0.59440 12.28941 -0.048 0.961
## BrandRJ -15.00836 14.67000 -1.023 0.307
## BrandRL -16.06863 14.66091 -1.096 0.274
## BrandRX -4.88683 12.30268 -0.397 0.691
## BrandRY -15.63530 12.40539 -1.260 0.208
## BrandSF -17.20566 18.74432 -0.918 0.359
## BrandTF -8.31906 13.32859 -0.624 0.533
## BrandTY -14.79733 13.57891 -1.090 0.276
## BrandVA -6.12332 19.06459 -0.321 0.748
## BrandVE -8.31584 13.04585 -0.637 0.524
## BrandVO -7.93330 13.45593 -0.590 0.556
## month2 -7.68282 4.89698 -1.569 0.117
## month3 -2.75872 5.08822 -0.542 0.588
## month4 2.54636 5.16142 0.493 0.622
## month5 0.60584 5.21460 0.116 0.908
## month6 -5.38599 4.82769 -1.116 0.265
## month7 -4.68335 6.21103 -0.754 0.451
## month8 -4.48277 4.89863 -0.915 0.361
## month9 -2.45666 5.05541 -0.486 0.627
## month10 -5.75226 5.33533 -1.078 0.282
## month11 2.15030 5.31743 0.404 0.686
## month12 -4.84616 5.42623 -0.893 0.372
##
## Residual standard error: 20 on 421 degrees of freedom
## Multiple R-squared: 0.1672, Adjusted R-squared: 0.01286
## F-statistic: 1.083 on 78 and 421 DF, p-value: 0.3076
anova(lm(formula = Order_Qty ~ promo + Brand + month, data = lm_cust_s2))
# p-value: 0.0177
lm_pd <- lm(formula = Order_Qty ~ promo + `Order Date`, data = lm_cust_s2)
anova(lm(formula = Order_Qty ~ promo + `Order Date`, data = lm_cust_s2))
summary(lm(formula = Order_Qty ~ promo + `Order Date`, data = lm_cust_s2))
##
## Call:
## lm(formula = Order_Qty ~ promo + `Order Date`, data = lm_cust_s2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -28.953 -8.500 -3.518 2.919 287.524
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 7.481e+01 1.359e+02 0.551 0.5822
## promoCODE F -1.667e+00 2.255e+01 -0.074 0.9411
## promoH15 2.146e+00 2.083e+01 0.103 0.9180
## promoHC18 -3.616e+00 2.853e+01 -0.127 0.8992
## promoLUX40 9.065e+00 2.057e+01 0.441 0.6596
## promoNASC150 1.178e+01 2.470e+01 0.477 0.6338
## promoNASC75 1.268e+00 2.852e+01 0.044 0.9646
## promoNB 1.238e+01 2.853e+01 0.434 0.6646
## promoNB40 2.641e+01 2.853e+01 0.926 0.3550
## promoOO15 -3.515e+00 2.853e+01 -0.123 0.9020
## promoOOX40 2.281e+01 2.470e+01 0.923 0.3562
## promoOther 6.914e+00 2.047e+01 0.338 0.7357
## promoOY12 3.860e+00 2.852e+01 0.135 0.8924
## promoPB3 -5.101e+00 2.852e+01 -0.179 0.8581
## promoPRE-SELL T -2.047e+00 2.852e+01 -0.072 0.9428
## promoPRE-SELL V 1.198e+01 2.852e+01 0.420 0.6746
## promoPRE SELL T 5.342e+00 2.853e+01 0.187 0.8515
## promoRB15 2.342e+01 2.471e+01 0.948 0.3438
## promoRSD 3.372e+01 2.873e+01 1.174 0.2410
## promoSUN1 4.838e+01 2.853e+01 1.696 0.0906 .
## promoSY1 1.127e+01 2.101e+01 0.536 0.5921
## promoSY100 6.722e+00 2.049e+01 0.328 0.7430
## promoSY1000 2.193e+00 2.349e+01 0.093 0.9256
## promoSY2 8.096e+00 2.265e+01 0.357 0.7210
## promoSY200 1.927e+01 2.160e+01 0.892 0.3728
## promoSY250 1.669e+01 2.106e+01 0.792 0.4286
## promoSY5 1.317e+01 2.269e+01 0.581 0.5618
## promoSYNERGY54 3.545e+00 2.193e+01 0.162 0.8717
## promoSYVE 1.438e+01 2.202e+01 0.653 0.5140
## promoUP1 4.190e+00 2.064e+01 0.203 0.8392
## promoUP3 -1.562e-01 2.115e+01 -0.007 0.9941
## promoVIP 2.588e+01 2.241e+01 1.155 0.2488
## promoVP1200 1.918e+00 2.852e+01 0.067 0.9464
## promoVPFP200 1.891e+01 2.209e+01 0.856 0.3925
## promoWC1 2.599e+01 2.162e+01 1.202 0.2300
## promoWild Card 3.443e+00 2.346e+01 0.147 0.8834
## `Order Date` -4.493e-08 9.036e-08 -0.497 0.6193
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 20.16 on 463 degrees of freedom
## Multiple R-squared: 0.06917, Adjusted R-squared: -0.003208
## F-statistic: 0.9557 on 36 and 463 DF, p-value: 0.5453
#p-value: 0.0169
lm_py <- lm(formula = Order_Qty ~ promo + year(`Order Date`), data = lm_cust_s2)
summary(lm(formula = Order_Qty ~ promo + year(`Order Date`), data = lm_cust_s2))
##
## Call:
## lm(formula = Order_Qty ~ promo + year(`Order Date`), data = lm_cust_s2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -29.536 -8.282 -3.282 2.952 287.093
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2781.638 5517.284 0.504 0.614
## promoCODE F -2.000 22.544 -0.089 0.929
## promoH15 2.000 20.826 0.096 0.924
## promoHC18 -4.000 28.517 -0.140 0.889
## promoLUX40 8.920 20.564 0.434 0.665
## promoNASC150 11.500 24.696 0.466 0.642
## promoNASC75 1.000 28.517 0.035 0.972
## promoNB 12.000 28.517 0.421 0.674
## promoNB40 26.000 28.517 0.912 0.362
## promoOO15 -4.000 28.517 -0.140 0.889
## promoOOX40 22.500 24.696 0.911 0.363
## promoOther 6.282 20.303 0.309 0.757
## promoOY12 4.000 28.517 0.140 0.889
## promoPB3 -5.000 28.517 -0.175 0.861
## promoPRE-SELL T -2.000 28.517 -0.070 0.944
## promoPRE-SELL V 12.000 28.517 0.421 0.674
## promoPRE SELL T 5.000 28.517 0.175 0.861
## promoRB15 23.000 24.696 0.931 0.352
## promoRSD 33.375 28.648 1.165 0.245
## promoSUN1 48.000 28.517 1.683 0.093 .
## promoSY1 10.495 20.745 0.506 0.613
## promoSY100 5.872 20.421 0.288 0.774
## promoSY1000 2.042 23.444 0.087 0.931
## promoSY2 6.975 22.258 0.313 0.754
## promoSY200 18.571 21.557 0.862 0.389
## promoSY250 16.563 21.026 0.788 0.431
## promoSY5 11.975 22.258 0.538 0.591
## promoSYNERGY54 2.500 21.562 0.116 0.908
## promoSYVE 13.518 21.730 0.622 0.534
## promoUP1 4.048 20.639 0.196 0.845
## promoUP3 -0.400 21.149 -0.019 0.985
## promoVIP 25.375 22.258 1.140 0.255
## promoVP1200 2.000 28.517 0.070 0.944
## promoVPFP200 18.800 22.089 0.851 0.395
## promoWC1 25.536 21.571 1.184 0.237
## promoWild Card 3.375 23.444 0.144 0.886
## year(`Order Date`) -1.375 2.735 -0.503 0.615
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 20.16 on 463 degrees of freedom
## Multiple R-squared: 0.06918, Adjusted R-squared: -0.003196
## F-statistic: 0.9558 on 36 and 463 DF, p-value: 0.545
anova(lm(formula = Order_Qty ~ promo + year(`Order Date`), data = lm_cust_s2))
#p-value: 0.4186 Not considering
summary(lm(formula = Order_Qty ~ month + Brand + Qt , data = lm_cust_s2))
##
## Call:
## lm(formula = Order_Qty ~ month + Brand + Qt, data = lm_cust_s2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -28.498 -8.874 -2.655 3.204 269.982
##
## Coefficients: (3 not defined because of singularities)
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 29.1269 12.3428 2.360 0.0187 *
## month2 -6.7943 4.6972 -1.446 0.1487
## month3 -0.9387 4.6792 -0.201 0.8411
## month4 0.5612 5.4616 0.103 0.9182
## month5 3.1061 5.3118 0.585 0.5590
## month6 -4.1376 5.0463 -0.820 0.4127
## month7 -8.9181 6.4702 -1.378 0.1688
## month8 -8.4441 5.2204 -1.618 0.1065
## month9 -6.2577 5.2956 -1.182 0.2380
## month10 -6.8754 5.3708 -1.280 0.2011
## month11 3.6261 5.5185 0.657 0.5115
## month12 -4.4138 5.3924 -0.819 0.4135
## BrandAX -12.6489 13.7450 -0.920 0.3579
## BrandBB -18.4439 16.5445 -1.115 0.2655
## BrandBE -9.4183 12.8866 -0.731 0.4652
## BrandBV -23.8384 18.4544 -1.292 0.1971
## BrandCH -15.4379 14.7833 -1.044 0.2969
## BrandDG -17.1604 13.0550 -1.314 0.1894
## BrandDY -13.9609 18.4087 -0.758 0.4486
## BrandEA -1.5132 14.7023 -0.103 0.9181
## BrandHC -6.3924 12.1845 -0.525 0.6001
## BrandMK -10.5573 12.5645 -0.840 0.4012
## BrandMU -16.3056 14.7329 -1.107 0.2690
## BrandOJ -24.5637 15.4420 -1.591 0.1124
## BrandOO -2.7353 12.2287 -0.224 0.8231
## BrandOX -4.3621 12.4842 -0.349 0.7269
## BrandOY -11.9135 12.4962 -0.953 0.3409
## BrandPH -15.2351 12.5483 -1.214 0.2253
## BrandPO -2.6429 16.5329 -0.160 0.8731
## BrandPP -18.7140 15.6163 -1.198 0.2314
## BrandPR -11.2298 12.1845 -0.922 0.3572
## BrandPS -21.2990 13.6998 -1.555 0.1207
## BrandRA -18.1680 18.4453 -0.985 0.3252
## BrandRB -5.1201 11.8603 -0.432 0.6662
## BrandRJ -21.5862 14.2457 -1.515 0.1304
## BrandRL -21.3110 14.2458 -1.496 0.1354
## BrandRX -9.4992 11.8849 -0.799 0.4246
## BrandRY -20.0697 12.0798 -1.661 0.0973 .
## BrandSF -23.3317 18.4149 -1.267 0.2058
## BrandTF -10.0557 12.8368 -0.783 0.4338
## BrandTY -15.4669 13.1312 -1.178 0.2395
## BrandVA -10.4880 16.5855 -0.632 0.5275
## BrandVE -11.9909 12.6397 -0.949 0.3433
## BrandVO -9.4192 13.0550 -0.722 0.4710
## QtQ1_18 -2.4528 3.7735 -0.650 0.5160
## QtQ2_17 -3.9472 3.6872 -1.071 0.2850
## QtQ2_18 NA NA NA NA
## QtQ3_17 4.5871 3.6216 1.267 0.2060
## QtQ3_18 NA NA NA NA
## QtQ4_17 -3.5326 4.0255 -0.878 0.3807
## QtQ4_18 NA NA NA NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 19.96 on 452 degrees of freedom
## Multiple R-squared: 0.1095, Adjusted R-squared: 0.01689
## F-statistic: 1.182 on 47 and 452 DF, p-value: 0.1983
#p-value: 0.0569
lm_pbms <- lm(formula = Order_Qty ~ Brand + promo + month + state, data = lm_cust_s2)
summary(lm(formula = Order_Qty ~ Brand + promo + month + state, data = lm_cust_s2))
##
## Call:
## lm(formula = Order_Qty ~ Brand + promo + month + state, data = lm_cust_s2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -32.491 -7.112 -1.416 4.217 266.166
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 24.34140 34.65968 0.702 0.483
## BrandAX -9.43580 14.86814 -0.635 0.526
## BrandBB 3.26352 20.54206 0.159 0.874
## BrandBE -4.70538 14.31167 -0.329 0.743
## BrandBV -24.68019 19.71887 -1.252 0.212
## BrandCH -13.64470 16.89896 -0.807 0.420
## BrandDG -11.70667 14.43260 -0.811 0.418
## BrandDY -2.10357 21.19808 -0.099 0.921
## BrandEA 3.85329 16.09139 0.239 0.811
## BrandHC -3.04371 13.57381 -0.224 0.823
## BrandMK -3.89967 13.81190 -0.282 0.778
## BrandMU -13.94565 16.40345 -0.850 0.396
## BrandOJ -13.25598 21.25816 -0.624 0.533
## BrandOO 2.54761 13.50548 0.189 0.850
## BrandOX 2.11429 14.18728 0.149 0.882
## BrandOY -8.54102 14.02066 -0.609 0.543
## BrandPH -13.08716 13.90990 -0.941 0.347
## BrandPO -8.05111 19.03369 -0.423 0.673
## BrandPP -11.38207 17.11624 -0.665 0.506
## BrandPR -9.58384 13.47975 -0.711 0.478
## BrandPS -19.73789 14.90218 -1.324 0.186
## BrandRA -11.81135 20.90181 -0.565 0.572
## BrandRB 0.15690 13.14801 0.012 0.990
## BrandRJ -16.69610 15.54028 -1.074 0.283
## BrandRL -14.13335 15.54060 -0.909 0.364
## BrandRX -4.14277 13.08811 -0.317 0.752
## BrandRY -15.86872 13.22231 -1.200 0.231
## BrandSF -12.07275 20.51086 -0.589 0.556
## BrandTF -9.60295 14.21696 -0.675 0.500
## BrandTY -17.47865 14.31132 -1.221 0.223
## BrandVA 2.48457 21.01856 0.118 0.906
## BrandVE -6.00615 13.88764 -0.432 0.666
## BrandVO -7.84678 14.36152 -0.546 0.585
## promoCODE F -18.94262 26.34560 -0.719 0.473
## promoH15 -10.24686 24.67117 -0.415 0.678
## promoHC18 -30.08249 36.89893 -0.815 0.415
## promoLUX40 -2.95482 24.43458 -0.121 0.904
## promoNASC150 -6.15996 29.06656 -0.212 0.832
## promoNASC75 -20.32947 33.47197 -0.607 0.544
## promoNB -14.42047 32.20278 -0.448 0.655
## promoNB40 8.05547 32.45870 0.248 0.804
## promoOO15 -9.87877 33.43834 -0.295 0.768
## promoOOX40 9.07036 29.26914 0.310 0.757
## promoOther -4.59889 24.10023 -0.191 0.849
## promoOY12 -1.68345 33.55792 -0.050 0.960
## promoPB3 -5.89979 35.89489 -0.164 0.870
## promoPRE-SELL T 1.58530 32.90659 0.048 0.962
## promoPRE-SELL V 2.69695 42.56437 0.063 0.950
## promoPRE SELL T -8.48946 33.32005 -0.255 0.799
## promoRB15 5.83293 28.61984 0.204 0.839
## promoRSD 12.36384 32.60438 0.379 0.705
## promoSUN1 31.21447 32.51273 0.960 0.338
## promoSY1 -3.24743 24.63739 -0.132 0.895
## promoSY100 -4.19219 24.48373 -0.171 0.864
## promoSY1000 -9.02390 27.02229 -0.334 0.739
## promoSY2 -7.78216 26.15571 -0.298 0.766
## promoSY200 -0.60026 25.81089 -0.023 0.981
## promoSY250 5.50742 24.76272 0.222 0.824
## promoSY5 1.01699 26.29332 0.039 0.969
## promoSYNERGY54 -12.69778 25.03677 -0.507 0.612
## promoSYVE 1.55493 25.47837 0.061 0.951
## promoUP1 -8.43329 24.65504 -0.342 0.733
## promoUP3 -16.34819 25.15020 -0.650 0.516
## promoVIP 11.54068 25.98017 0.444 0.657
## promoVP1200 -24.93114 33.35503 -0.747 0.455
## promoVPFP200 6.11276 25.25616 0.242 0.809
## promoWC1 16.71279 25.51141 0.655 0.513
## promoWild Card -9.00834 27.75119 -0.325 0.746
## month2 -7.77109 5.25957 -1.478 0.140
## month3 -1.81593 5.45449 -0.333 0.739
## month4 3.52338 5.60733 0.628 0.530
## month5 2.47287 5.66723 0.436 0.663
## month6 -4.91644 5.22653 -0.941 0.347
## month7 -5.71545 6.65115 -0.859 0.391
## month8 -4.15867 5.32694 -0.781 0.435
## month9 -1.78900 5.43214 -0.329 0.742
## month10 -4.84808 5.70788 -0.849 0.396
## month11 2.82944 5.72757 0.494 0.622
## month12 -4.47122 5.85865 -0.763 0.446
## stateAL -6.44711 25.79800 -0.250 0.803
## stateAR 4.55791 26.88410 0.170 0.865
## stateAZ 4.27815 22.42990 0.191 0.849
## stateCA 8.71411 21.16914 0.412 0.681
## stateCO -2.18563 21.89649 -0.100 0.921
## stateCT -0.98745 22.12531 -0.045 0.964
## stateFL 7.44931 21.29390 0.350 0.727
## stateGA 5.07439 21.68191 0.234 0.815
## stateGU 47.27253 31.17686 1.516 0.130
## stateHI -6.74003 24.61812 -0.274 0.784
## stateIA 8.16987 24.47813 0.334 0.739
## stateID 3.05964 30.14644 0.101 0.919
## stateIL -0.01358 21.59389 -0.001 0.999
## stateIN -3.30616 22.87731 -0.145 0.885
## stateKS -2.55266 22.50744 -0.113 0.910
## stateKY 4.00471 22.19660 0.180 0.857
## stateLA 6.71099 25.29071 0.265 0.791
## stateMA -3.78333 22.73121 -0.166 0.868
## stateMD 5.02998 23.46099 0.214 0.830
## stateME -4.42156 24.23415 -0.182 0.855
## stateMI -5.03300 22.02199 -0.229 0.819
## stateMN -5.31793 23.62548 -0.225 0.822
## stateMO 10.49268 22.95868 0.457 0.648
## stateMS -2.06425 22.64035 -0.091 0.927
## stateMT 2.76483 25.87290 0.107 0.915
## stateNC -0.08450 21.87626 -0.004 0.997
## stateND -0.97132 30.59464 -0.032 0.975
## stateNE -11.89414 23.49896 -0.506 0.613
## stateNH 1.09062 24.90381 0.044 0.965
## stateNJ 6.25181 21.68265 0.288 0.773
## stateNM -1.33418 30.54518 -0.044 0.965
## stateNV 6.17007 22.59854 0.273 0.785
## stateNY 3.86561 21.33141 0.181 0.856
## stateOH -2.11693 22.72454 -0.093 0.926
## stateOK 6.40163 22.49315 0.285 0.776
## stateOR 1.12752 22.83891 0.049 0.961
## statePA -5.45929 21.71992 -0.251 0.802
## statePR 13.63346 22.64758 0.602 0.548
## stateRI -1.12313 29.85211 -0.038 0.970
## stateSC -5.70310 24.05793 -0.237 0.813
## stateTN 4.39440 22.94158 0.192 0.848
## stateTX 3.37447 21.21044 0.159 0.874
## stateUT -9.07763 23.42049 -0.388 0.699
## stateVA -4.93161 24.55915 -0.201 0.841
## stateVT -1.69813 29.82681 -0.057 0.955
## stateWA -6.56651 23.21941 -0.283 0.777
## stateWI -8.05133 29.78809 -0.270 0.787
## stateWV -1.75182 31.03483 -0.056 0.955
## stateWY -9.00991 34.24992 -0.263 0.793
##
## Residual standard error: 20.47 on 372 degrees of freedom
## Multiple R-squared: 0.2294, Adjusted R-squared: -0.0337
## F-statistic: 0.8719 on 127 and 372 DF, p-value: 0.8179
# p-value: 0.08366
lmdata<-na.omit(lm_cust_s2)
lm_qbpms <-(lm(formula = Order_Qty ~ Qt + Brand + promo + `Order Date`, data = lm_cust_s2))
summary(lm_qbpms)
##
## Call:
## lm(formula = Order_Qty ~ Qt + Brand + promo + `Order Date`, data = lm_cust_s2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -24.249 -8.121 -1.825 3.312 274.521
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 9.367e+02 6.961e+02 1.346 0.179
## QtQ1_18 1.764e+01 1.845e+01 0.956 0.340
## QtQ2_17 2.488e+00 5.876e+00 0.423 0.672
## QtQ2_18 2.783e+01 2.126e+01 1.309 0.191
## QtQ3_17 1.228e+01 1.384e+01 0.887 0.375
## QtQ3_18 2.679e+01 2.462e+01 1.088 0.277
## QtQ4_17 1.311e+01 1.537e+01 0.853 0.394
## QtQ4_18 3.726e+01 2.765e+01 1.348 0.178
## BrandAX -8.963e+00 1.418e+01 -0.632 0.528
## BrandBB -7.788e+00 1.917e+01 -0.406 0.685
## BrandBE -5.683e+00 1.346e+01 -0.422 0.673
## BrandBV -1.389e+01 1.877e+01 -0.740 0.460
## BrandCH -7.168e+00 1.606e+01 -0.446 0.656
## BrandDG -1.157e+01 1.360e+01 -0.850 0.396
## BrandDY -7.025e+00 1.897e+01 -0.370 0.711
## BrandEA 5.246e+00 1.526e+01 0.344 0.731
## BrandHC -1.138e+00 1.274e+01 -0.089 0.929
## BrandMK -4.354e+00 1.310e+01 -0.332 0.740
## BrandMU -1.043e+01 1.580e+01 -0.660 0.509
## BrandOJ -1.804e+01 1.694e+01 -1.065 0.288
## BrandOO 4.466e+00 1.272e+01 0.351 0.726
## BrandOX 2.964e+00 1.313e+01 0.226 0.821
## BrandOY -5.354e+00 1.311e+01 -0.408 0.683
## BrandPH -1.153e+01 1.295e+01 -0.891 0.374
## BrandPO -1.582e+00 1.722e+01 -0.092 0.927
## BrandPP -1.017e+01 1.593e+01 -0.639 0.523
## BrandPR -5.565e+00 1.261e+01 -0.441 0.659
## BrandPS -1.667e+01 1.419e+01 -1.174 0.241
## BrandRA -1.371e+01 1.989e+01 -0.689 0.491
## BrandRB 9.941e-01 1.238e+01 0.080 0.936
## BrandRJ -1.359e+01 1.479e+01 -0.918 0.359
## BrandRL -1.493e+01 1.469e+01 -1.016 0.310
## BrandRX -3.321e+00 1.237e+01 -0.268 0.789
## BrandRY -1.330e+01 1.247e+01 -1.066 0.287
## BrandSF -1.496e+01 1.875e+01 -0.798 0.425
## BrandTF -6.670e+00 1.336e+01 -0.499 0.618
## BrandTY -1.323e+01 1.376e+01 -0.962 0.337
## BrandVA -7.796e+00 1.910e+01 -0.408 0.683
## BrandVE -7.050e+00 1.310e+01 -0.538 0.591
## BrandVO -7.115e+00 1.348e+01 -0.528 0.598
## promoCODE F -5.408e+00 2.519e+01 -0.215 0.830
## promoH15 -4.563e-01 2.333e+01 -0.020 0.984
## promoHC18 -5.674e-01 3.413e+01 -0.017 0.987
## promoLUX40 8.297e+00 2.307e+01 0.360 0.719
## promoNASC150 1.146e+01 2.769e+01 0.414 0.679
## promoNASC75 7.210e-01 3.120e+01 0.023 0.982
## promoNB 6.543e+00 3.064e+01 0.214 0.831
## promoNB40 2.758e+01 3.079e+01 0.896 0.371
## promoOO15 -7.957e+00 3.067e+01 -0.259 0.795
## promoOOX40 1.546e+01 2.726e+01 0.567 0.571
## promoOther 2.207e+00 2.557e+01 0.086 0.931
## promoOY12 2.584e-01 3.064e+01 0.008 0.993
## promoPB3 4.475e+00 3.241e+01 0.138 0.890
## promoPRE-SELL T -3.141e+00 3.080e+01 -0.102 0.919
## promoPRE-SELL V 1.236e+01 3.338e+01 0.370 0.711
## promoPRE SELL T 6.725e+00 3.116e+01 0.216 0.829
## promoRB15 1.811e+01 2.718e+01 0.666 0.506
## promoRSD 2.192e+01 3.274e+01 0.669 0.504
## promoSUN1 4.260e+01 3.064e+01 1.390 0.165
## promoSY1 5.383e+00 2.604e+01 0.207 0.836
## promoSY100 5.135e+00 2.572e+01 0.200 0.842
## promoSY1000 4.657e+00 2.842e+01 0.164 0.870
## promoSY2 7.855e-01 2.733e+01 0.029 0.977
## promoSY200 1.929e+01 2.483e+01 0.777 0.438
## promoSY250 1.631e+01 2.624e+01 0.622 0.535
## promoSY5 8.146e+00 2.736e+01 0.298 0.766
## promoSYNERGY54 -6.864e+00 2.623e+01 -0.262 0.794
## promoSYVE 1.447e+01 2.697e+01 0.537 0.592
## promoUP1 3.317e+00 2.318e+01 0.143 0.886
## promoUP3 -3.213e+00 2.376e+01 -0.135 0.892
## promoVIP 1.868e+01 2.751e+01 0.679 0.498
## promoVP1200 -5.154e+00 3.045e+01 -0.169 0.866
## promoVPFP200 1.819e+01 2.353e+01 0.773 0.440
## promoWC1 2.403e+01 2.495e+01 0.963 0.336
## promoWild Card 4.344e+00 2.898e+01 0.150 0.881
## `Order Date` -6.197e-07 4.681e-07 -1.324 0.186
##
## Residual standard error: 20.02 on 424 degrees of freedom
## Multiple R-squared: 0.1595, Adjusted R-squared: 0.01078
## F-statistic: 1.072 on 75 and 424 DF, p-value: 0.3303
From above analyis I would use differnt model to valdiate the result. Lets take model lm_pbm which is model for promotion + brand + month would predict order Quanity.
To assess whether the linear model is reliable, we need to check for (1) linearity, (2) nearly normal residuals, and (3) constant variability. (4) Residuals are independent Residual = Observed value - Predicted value
# From above analyis I would use differnt model to valdiate the result. Lets take model lm_pbm which is model for promotion + brand + month would predict order Quanity .
# To assess whether the linear model is reliable, we need to check for
#(1) linearity,
#(2) nearly normal residuals, and
#(3) constant variability.
#(4) Residuals are independent
# Residual = Observed value - Predicted value
library(DATA606)
plot_ss(x = lm_cust_s2$Order_Qty, y = lm_pbm$residuals,showSquares = TRUE)
## Click two points to make a line.
## Call:
## lm(formula = y ~ x, data = pts)
##
## Coefficients:
## (Intercept) x
## -12.2794 0.8328
##
## Sum of Squares: 28156.54
# # (1) Linear association: The residuals plot shows a random scatter.
#Based on the plot we can clearly say that there is apparent pattern in the distribution as the numbers appear to be group and outlier are close to the regression line, so it can be treated as strong corelation and can be considered as a linear relationship.
# # (2) Nearly normal residuals: To check this condition, we can look at a histogram
hist(lm_pbm$residuals)
# or a normal probability plot of the residuals.
#It seems the plot is slightly skewed left,
qqnorm(lm_pbm$residuals)
qqline(lm_pbm$residuals) # adds diagonal line to the normal prob plot
# (3) we can say that its also Nearly normal residuals even though its right skewed with few outliers .
# (4)Residuals can be treated as independent as sample is drawn from independent .
# plot on sample
ggplot(data = lm_cust_s2,mapping = aes(y=lm_cust_s2$Order_Qty ,x= lm_cust_s2$promo))+ geom_point() + geom_smooth(method = "lm",se=FALSE) + geom_abline(slope = lm_pbm$coefficients[8], intercept = lm_pbm$coefficients[1], color="red")
# regression Line population data of 2 year.
(ggplot(data = mkt_Data,mapping = aes(y=mkt_Data$`Order Quantity` ,x= mkt_Data$`External Description`))+ geom_point() + geom_smooth(method = "lm",se=FALSE) + geom_abline(slope = lm_pbm$coefficients[8], intercept = lm_pbm$coefficients[1], color="red") )
# Lets plot on by Order Date
# To assess whether the linear model is reliable, we need to check for
#(1) linearity,
#(2) nearly normal residuals, and
#(3) constant variability.
#(4) Residuals are independent
#
plot_ss(x = lm_cust_s2$Order_Qty, y = lm_pd$residuals,showSquares = TRUE) # Linear association
## Click two points to make a line.
## Call:
## lm(formula = y ~ x, data = pts)
##
## Coefficients:
## (Intercept) x
## -13.7242 0.9308
##
## Sum of Squares: 13021.47
hist(lm_pd$residuals) # Right skewed
qqnorm(lm_pd$residuals)
qqline(lm_pd$residuals) # very much on the regression line, Nearly normal residuals even though its right skewed
# On Sample
ggplot(data = lm_cust_s2,mapping = aes(y=lm_cust_s2$Order_Qty ,x= lm_cust_s2$`Order Date`))+ geom_point() + geom_smooth(method = "lm",se=FALSE) +
geom_abline(slope = lm_pd$coefficients[8], intercept = lm_pd$coefficients[1], color="green")+
geom_abline(slope = lm_pbm$coefficients[8], intercept = lm_pbm$coefficients[1], color="red")
# On Population
ggplot(data = mkt_Data,mapping = aes(y = mkt_Data$`Order Quantity`,x= mkt_Data$Brand))+ geom_point() + geom_smooth(method = "lm",se=FALSE) + geom_abline(slope = lm_pd$coefficients[8], intercept = lm_pd$coefficients[1], color="red") +
geom_abline(slope = lm_pbm$coefficients[8], intercept = lm_pbm$coefficients[1], color="green")
plot(lm_pbm)
## Warning: not plotting observations with leverage one:
## 72, 100, 139, 196, 213, 217, 219, 414, 465, 470, 482
## Warning: not plotting observations with leverage one:
## 72, 100, 139, 196, 213, 217, 219, 414, 465, 470, 482
## Warning in sqrt(crit * p * (1 - hh)/hh): NaNs produced
## Warning in sqrt(crit * p * (1 - hh)/hh): NaNs produced
plot(lm_pd)
## Warning: not plotting observations with leverage one:
## 72, 100, 139, 196, 213, 217, 219, 414, 465, 470, 482
## Warning: not plotting observations with leverage one:
## 72, 100, 139, 196, 213, 217, 219, 414, 465, 470, 482
## Warning in sqrt(crit * p * (1 - hh)/hh): NaNs produced
## Warning in sqrt(crit * p * (1 - hh)/hh): NaNs produced
Residuals: We can see that the multiple regression model1 has a smaller range for the residuals as compared with Model 2: (Model 1) -59 to 339 vs.(model 2) -62.02 to 356.44. Secondly the median of the multiple regression model 1 is much closer to 0 than the model 2 regression model.
Coefficients: (Intercept): The intercept is the left over when you average the independent and dependent variable. In the simple regression Model 1 we see that the intercept is 20.02172 which is close tp ZERO, and Model 2 has much larger intercept ie. 266.9 (format( 2.669e+02, scientific = FALSE)) meaning there’s a fair amount left over. Model 1 looks close fit with nearrest to ZERO intercept.
promo: Both multiple regression model shows that when we add promo variable it’s multiplying this variable times the numeric (ordinal) value of the Promotion code.So for every promocode in the year, you add an additional estimated column unit value in sales. For example : promoRSD will add 130 Unit each MOnth.promoWild Card will add 53 Unit
Brand : So far every brand addition would add resepctive value in the sales unit by multiplying the brand intercept with its ordinal vlaue. FOr example addition of brand AX would add 3 unit each month.
Month: When we add in the Month variable it’s multiplying this variable times the numeric (ordinal) value of the month. For example July and August
##
## Call:
## lm(formula = Order_Qty ~ promo + Brand + month, data = lm_cust_s2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -28.914 -8.133 -1.654 3.478 272.944
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 26.13481 26.10286 1.001 0.317
## promoCODE F -15.96890 25.23730 -0.633 0.527
## promoH15 -8.72719 23.45000 -0.372 0.710
## promoHC18 -19.24662 34.26227 -0.562 0.575
## promoLUX40 0.65737 23.17376 0.028 0.977
## promoNASC150 -1.28252 27.65930 -0.046 0.963
## promoNASC75 -14.85914 31.18716 -0.476 0.634
## promoNB -6.14625 30.76470 -0.200 0.842
## promoNB40 15.07273 30.93316 0.487 0.626
## promoOO15 -16.15442 30.59427 -0.528 0.598
## promoOOX40 6.81802 27.41124 0.249 0.804
## promoOther -3.73615 22.87707 -0.163 0.870
## promoOY12 -7.04911 31.00791 -0.227 0.820
## promoPB3 -6.01193 32.81257 -0.183 0.855
## promoPRE-SELL T -4.13293 30.79075 -0.134 0.893
## promoPRE-SELL V 7.67132 33.41142 0.230 0.819
## promoPRE SELL T -5.42158 31.26403 -0.173 0.862
## promoRB15 7.84967 27.13088 0.289 0.772
## promoRSD 16.07839 30.92792 0.520 0.603
## promoSUN1 29.85375 30.76470 0.970 0.332
## promoSY1 0.03163 23.35211 0.001 0.999
## promoSY100 -0.56330 23.22642 -0.024 0.981
## promoSY1000 -3.43163 25.67911 -0.134 0.894
## promoSY2 -4.81010 24.79152 -0.194 0.846
## promoSY200 8.62250 24.36471 0.354 0.724
## promoSY250 8.06814 23.49242 0.343 0.731
## promoSY5 3.93312 24.81882 0.158 0.874
## promoSYNERGY54 -9.85176 23.61471 -0.417 0.677
## promoSYVE 3.35126 24.29424 0.138 0.890
## promoUP1 -5.59888 23.29931 -0.240 0.810
## promoUP3 -13.01644 23.86255 -0.545 0.586
## promoVIP 14.93715 24.92897 0.599 0.549
## promoVP1200 -13.31577 30.77976 -0.433 0.666
## promoVPFP200 10.07814 23.99677 0.420 0.675
## promoWC1 17.74550 24.22135 0.733 0.464
## promoWild Card -4.61956 26.46511 -0.175 0.862
## BrandAX -10.95095 13.99807 -0.782 0.434
## BrandBB -3.49403 19.13093 -0.183 0.855
## BrandBE -4.82203 13.43485 -0.359 0.720
## BrandBV -19.33190 18.85157 -1.025 0.306
## BrandCH -10.45199 16.05497 -0.651 0.515
## BrandDG -13.11649 13.48968 -0.972 0.331
## BrandDY -6.86874 18.90344 -0.363 0.717
## BrandEA 4.50472 15.22928 0.296 0.768
## BrandHC -2.81904 12.67625 -0.222 0.824
## BrandMK -5.46062 13.01448 -0.420 0.675
## BrandMU -12.97826 15.65353 -0.829 0.408
## BrandOJ -17.12288 16.84112 -1.017 0.310
## BrandOO 2.50665 12.69621 0.197 0.844
## BrandOX 1.61952 13.06314 0.124 0.901
## BrandOY -7.08570 12.97111 -0.546 0.585
## BrandPH -11.87732 12.88164 -0.922 0.357
## BrandPO -3.96044 17.19708 -0.230 0.818
## BrandPP -13.70844 16.01366 -0.856 0.392
## BrandPR -7.81338 12.60822 -0.620 0.536
## BrandPS -17.09130 14.11834 -1.211 0.227
## BrandRA -12.97364 19.96227 -0.650 0.516
## BrandRB -0.59440 12.28941 -0.048 0.961
## BrandRJ -15.00836 14.67000 -1.023 0.307
## BrandRL -16.06863 14.66091 -1.096 0.274
## BrandRX -4.88683 12.30268 -0.397 0.691
## BrandRY -15.63530 12.40539 -1.260 0.208
## BrandSF -17.20566 18.74432 -0.918 0.359
## BrandTF -8.31906 13.32859 -0.624 0.533
## BrandTY -14.79733 13.57891 -1.090 0.276
## BrandVA -6.12332 19.06459 -0.321 0.748
## BrandVE -8.31584 13.04585 -0.637 0.524
## BrandVO -7.93330 13.45593 -0.590 0.556
## month2 -7.68282 4.89698 -1.569 0.117
## month3 -2.75872 5.08822 -0.542 0.588
## month4 2.54636 5.16142 0.493 0.622
## month5 0.60584 5.21460 0.116 0.908
## month6 -5.38599 4.82769 -1.116 0.265
## month7 -4.68335 6.21103 -0.754 0.451
## month8 -4.48277 4.89863 -0.915 0.361
## month9 -2.45666 5.05541 -0.486 0.627
## month10 -5.75226 5.33533 -1.078 0.282
## month11 2.15030 5.31743 0.404 0.686
## month12 -4.84616 5.42623 -0.893 0.372
##
## Residual standard error: 20 on 421 degrees of freedom
## Multiple R-squared: 0.1672, Adjusted R-squared: 0.01286
## F-statistic: 1.083 on 78 and 421 DF, p-value: 0.3076
## $promo
## [1] "CHANEL PRE" "CODE F" "H15" "HC18" "LUX40"
## [6] "NASC150" "NASC75" "NB" "NB40" "OO15"
## [11] "OOX40" "Other" "OY12" "PB3" "PRE-SELL T"
## [16] "PRE-SELL V" "PRE SELL T" "RB15" "RSD" "SUN1"
## [21] "SY1" "SY100" "SY1000" "SY2" "SY200"
## [26] "SY250" "SY5" "SYNERGY54" "SYVE" "UP1"
## [31] "UP3" "VIP" "VP1200" "VPFP200" "WC1"
## [36] "Wild Card"
##
## $Brand
## [1] "AR" "AX" "BB" "BE" "BV" "CH" "DG" "DY" "EA" "HC" "MK" "MU" "OJ" "OO"
## [15] "OX" "OY" "PH" "PO" "PP" "PR" "PS" "RA" "RB" "RJ" "RL" "RX" "RY" "SF"
## [29] "TF" "TY" "VA" "VE" "VO"
##
## $month
## [1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12"
## [1] "Regression Formula Y = 26.13 + -15.97 * promoCODE F + -8.73 * promoH15 + -19.25 * promoHC18 + 0.66 * promoLUX40 + -1.28 * promoNASC150 + -14.86 * promoNASC75 + -6.15 * promoNB + 15.07 * promoNB40 + -16.15 * promoOO15 + 6.82 * promoOOX40 + -3.74 * promoOther + -7.05 * promoOY12 + -6.01 * promoPB3 + -4.13 * promoPRE-SELL T + 7.67 * promoPRE-SELL V + -5.42 * promoPRE SELL T + 7.85 * promoRB15 + 16.08 * promoRSD + 29.85 * promoSUN1 + 0.03 * promoSY1 + -0.56 * promoSY100 + -3.43 * promoSY1000 + -4.81 * promoSY2 + 8.62 * promoSY200 + 8.07 * promoSY250 + 3.93 * promoSY5 + -9.85 * promoSYNERGY54 + 3.35 * promoSYVE + -5.6 * promoUP1 + -13.02 * promoUP3 + 14.94 * promoVIP + -13.32 * promoVP1200 + 10.08 * promoVPFP200 + 17.75 * promoWC1 + -4.62 * promoWild Card + -10.95 * BrandAX + -3.49 * BrandBB + -4.82 * BrandBE + -19.33 * BrandBV + -10.45 * BrandCH + -13.12 * BrandDG + -6.87 * BrandDY + 4.5 * BrandEA + -2.82 * BrandHC + -5.46 * BrandMK + -12.98 * BrandMU + -17.12 * BrandOJ + 2.51 * BrandOO + 1.62 * BrandOX + -7.09 * BrandOY + -11.88 * BrandPH + -3.96 * BrandPO + -13.71 * BrandPP + -7.81 * BrandPR + -17.09 * BrandPS + -12.97 * BrandRA + -0.59 * BrandRB + -15.01 * BrandRJ + -16.07 * BrandRL + -4.89 * BrandRX + -15.64 * BrandRY + -17.21 * BrandSF + -8.32 * BrandTF + -14.8 * BrandTY + -6.12 * BrandVA + -8.32 * BrandVE + -7.93 * BrandVO + -7.68 * month2 + -2.76 * month3 + 2.55 * month4 + 0.61 * month5 + -5.39 * month6 + -4.68 * month7 + -4.48 * month8 + -2.46 * month9 + -5.75 * month10 + 2.15 * month11 + -4.85 * month12 + e"
##
## Call:
## lm(formula = Order_Qty ~ promo + `Order Date`, data = lm_cust_s2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -28.953 -8.500 -3.518 2.919 287.524
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 7.481e+01 1.359e+02 0.551 0.5822
## promoCODE F -1.667e+00 2.255e+01 -0.074 0.9411
## promoH15 2.146e+00 2.083e+01 0.103 0.9180
## promoHC18 -3.616e+00 2.853e+01 -0.127 0.8992
## promoLUX40 9.065e+00 2.057e+01 0.441 0.6596
## promoNASC150 1.178e+01 2.470e+01 0.477 0.6338
## promoNASC75 1.268e+00 2.852e+01 0.044 0.9646
## promoNB 1.238e+01 2.853e+01 0.434 0.6646
## promoNB40 2.641e+01 2.853e+01 0.926 0.3550
## promoOO15 -3.515e+00 2.853e+01 -0.123 0.9020
## promoOOX40 2.281e+01 2.470e+01 0.923 0.3562
## promoOther 6.914e+00 2.047e+01 0.338 0.7357
## promoOY12 3.860e+00 2.852e+01 0.135 0.8924
## promoPB3 -5.101e+00 2.852e+01 -0.179 0.8581
## promoPRE-SELL T -2.047e+00 2.852e+01 -0.072 0.9428
## promoPRE-SELL V 1.198e+01 2.852e+01 0.420 0.6746
## promoPRE SELL T 5.342e+00 2.853e+01 0.187 0.8515
## promoRB15 2.342e+01 2.471e+01 0.948 0.3438
## promoRSD 3.372e+01 2.873e+01 1.174 0.2410
## promoSUN1 4.838e+01 2.853e+01 1.696 0.0906 .
## promoSY1 1.127e+01 2.101e+01 0.536 0.5921
## promoSY100 6.722e+00 2.049e+01 0.328 0.7430
## promoSY1000 2.193e+00 2.349e+01 0.093 0.9256
## promoSY2 8.096e+00 2.265e+01 0.357 0.7210
## promoSY200 1.927e+01 2.160e+01 0.892 0.3728
## promoSY250 1.669e+01 2.106e+01 0.792 0.4286
## promoSY5 1.317e+01 2.269e+01 0.581 0.5618
## promoSYNERGY54 3.545e+00 2.193e+01 0.162 0.8717
## promoSYVE 1.438e+01 2.202e+01 0.653 0.5140
## promoUP1 4.190e+00 2.064e+01 0.203 0.8392
## promoUP3 -1.562e-01 2.115e+01 -0.007 0.9941
## promoVIP 2.588e+01 2.241e+01 1.155 0.2488
## promoVP1200 1.918e+00 2.852e+01 0.067 0.9464
## promoVPFP200 1.891e+01 2.209e+01 0.856 0.3925
## promoWC1 2.599e+01 2.162e+01 1.202 0.2300
## promoWild Card 3.443e+00 2.346e+01 0.147 0.8834
## `Order Date` -4.493e-08 9.036e-08 -0.497 0.6193
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 20.16 on 463 degrees of freedom
## Multiple R-squared: 0.06917, Adjusted R-squared: -0.003208
## F-statistic: 0.9557 on 36 and 463 DF, p-value: 0.5453
## $promo
## [1] "CHANEL PRE" "CODE F" "H15" "HC18" "LUX40"
## [6] "NASC150" "NASC75" "NB" "NB40" "OO15"
## [11] "OOX40" "Other" "OY12" "PB3" "PRE-SELL T"
## [16] "PRE-SELL V" "PRE SELL T" "RB15" "RSD" "SUN1"
## [21] "SY1" "SY100" "SY1000" "SY2" "SY200"
## [26] "SY250" "SY5" "SYNERGY54" "SYVE" "UP1"
## [31] "UP3" "VIP" "VP1200" "VPFP200" "WC1"
## [36] "Wild Card"
Analyis of Variance table
anova(lm_pbm,lm_pd)
Function perfroms an analysis of variance of the two models using an F-test to assess the significanxe of the differences.
We can see Model has decreased the Sum of the Squared error, and the value of 0.1977 says that we can be 80% confidence in saying that they models are different.
Using test and sample data we will see how good our Model is. We wil luse Absolute Mean error of the model and decide which regression models works well for the sample.
# lm_cust_s2
# lm_cust_s2 <- lm_cust[sample(nrow(lm_cust),500),]
# lm_cust_s2$month <- month(lm_cust_s2$`Order Date`)
# lm_cust_s2$month <- as.factor(lm_cust_s2$month )
# names(lm_cust_s2)
#
# Uisng same sample to test lm_cust_s2 , creating sample of 500 more to test.
lm_cust_t1 <- lm_cust_s2
lm_cust_t2 <- lm_cust[sample(nrow(lm_cust),500),]
lm_cust_t2$month <- month(lm_cust_t2$`Order Date`)
lm_cust_t2$month <- as.factor(lm_cust_t2$month )
names(lm_cust_t2)
## [1] "KUNNR_NEW" "Qt" "Brand" "Order Date" "promo"
## [6] "city" "state" "Order_Qty" "Doll_Val" "month"
lm_pbm1 <- update(lm_pbm,lm_cust_s2)
# Predict main train data
lm_pred_pbm <- predict(lm_pbm,lm_cust_t1)
lm_pred_pd <- predict(lm_pd,lm_cust_t1)
lm_pred_qbpms <- predict(lm_qbpms,lm_cust_t1)
mean(abs(lm_cust_t1$Order_Qty- lm_cust_t1$Order_Qty))
## [1] 0
mean(abs(lm_pred_pbm - lm_cust_t1$Order_Qty))
## [1] 9.284085
mean(abs(lm_pred_pd - lm_cust_t1$Order_Qty))
## [1] 9.7031
mean(abs(lm_pred_qbpms - lm_cust_t1$Order_Qty))
## [1] 9.31299
# Using test data of new set
# lm_pbm <- lm(formula = Order_Qty ~ promo + Brand + month, data = lm_cust_t2)
update
## standardGeneric for "update" defined from package "stats"
##
## function (object, ...)
## standardGeneric("update")
## <environment: 0x000000001075c9b8>
## Methods may be defined for arguments: object
## Use showMethods("update") for currently available ones.
lm_pred_pbm <- predict(lm(formula = Order_Qty ~ promo + Brand + month, data = lm_cust_t2),lm_cust_t2)
lm_pred_pd <- predict(lm(formula = Order_Qty ~ promo + `Order Date` , data = lm_cust_t2),lm_cust_t2)
lm_pred_qbpms <- predict(lm(formula = Order_Qty ~ Qt + Brand+promo +month+ state , data = lm_cust_t2),lm_cust_t2)
## Warning in predict.lm(lm(formula = Order_Qty ~ Qt + Brand + promo + month
## + : prediction from a rank-deficient fit may be misleading
mean(abs(lm_cust_t2$Order_Qty- lm_cust_t2$Order_Qty))
## [1] 0
mean(abs(lm_pred_pbm - lm_cust_t2$Order_Qty))
## [1] 7.633058
mean(abs(lm_pred_pd - lm_cust_t2$Order_Qty))
## [1] 8.786852
mean(abs(lm_pred_qbpms - lm_cust_t2$Order_Qty))
## [1] 7.365802
From above mean errors we can see that model 1 with regession model with formula lm(formula = Order_Qty ~ promo + Brand + month, data = lm_cust_t2) is well close to zero in terms of mean absulate error.
Write a brief summary of your findings without repeating your statements from earlier. Also include a discussion of what you have learned about your research question and the data you collected. You may also want to include ideas for possible future research. #
https://stats.stackexchange.com/questions/405243/compare-sales-data-over-time-in-sequence
https://www.machinelearningplus.com/machine-learning/complete-introduction-linear-regression-r/
https://university.business-science.io/courses/541056/lectures/9826285 https://www.youtube.com/watch?v=SvKv375sacA
Remove this section if you don’t have an appendix